Arnab Chakraborty has Published 4293 Articles

Find safe cells in a matrix in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Dec-2019 13:07:14

160 Views

Suppose we have a matrix mat[][]. It has character Z and P. The Z is the zombie and P is the plant. And another character * is a bare land. A zombie can attack the plant, when plant is adjacent to zombie. We have to find number of plants, that ... Read More

Find repeated character present first in a string in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Dec-2019 13:03:35

424 Views

Suppose we have a string; we have to find first character that is repeated. So is the string is “Hello Friends”, the first repeated character will be l. As there are two l’s one after another.To solve this, we will use the hashing technique. Create one hash table, scan each ... Read More

Find product of prime numbers between 1 to n in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Dec-2019 12:59:05

360 Views

Suppose we have a number n. We have to find the product of prime numbers between 1 to n. So if n = 7, then output will be 210, as 2 * 3 * 5 * 7 = 210.We will use the Sieve of Eratosthenes method to find all primes. ... Read More

Find prime number K in an array such that (A[i] % K) is maximum in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Dec-2019 12:56:56

127 Views

Suppose we have an array A with n integers. We have to find one element K such that K is prime, and A[i] mod K is maximum for all valid i among all possible values of K. If no such numbers are found, then return -1. For example, if A ... Read More

Find the multiple of x which is closest to a^b in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Dec-2019 12:54:03

135 Views

Suppose we have three integers, a, b and x. The task is to get the multiple of x, which is closest to ab. So if a = 5, b = 4 and x = 3, then output will be 624. As 54 = 625, and 624 is the multiple of ... Read More

Find permutation of n which is divisible by 3 but not divisible by 6 in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Dec-2019 12:53:38

115 Views

Suppose we have a number n, and we have to find the permutation of this number, that is divisible by 3, but not divisible by 6. If no such value can be made, then return -1. For example, if n is 336, then the output can be 363.As we know ... Read More

Find permutation of first N natural numbers that satisfies the given condition in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Dec-2019 12:52:46

226 Views

Suppose we have two integers N and K, and we have to find the permutation P of first N natural numbers such that there are exactly K elements which satisfies the condition GCD(P[i], i) > 1 for all 1

Find pair with maximum difference in any column of a Matrix in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Dec-2019 12:50:47

129 Views

Suppose we have one matrix or order NxN. We have to find a pair of elements which forms maximum difference from any column of the matrix. So if the matrix is like −123535967So output will be 8. As the pair is (1, 9) from column 0.The idea is simple, we ... Read More

Find the missing number in Geometric Progression in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Dec-2019 12:48:57

152 Views

Suppose we have an array that represents elements of geometric progression in order. One element is missing. We have to find the missing element. So if arr = [1, 3, 27, 81], output is 9, as 9 is missing.Using binary search, we can solve this problem. We will go to ... Read More

Find the missing number in Arithmetic Progression in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Dec-2019 12:47:11

202 Views

Suppose we have an array that represents elements of arithmetic progression in order. One element is missing. We have to find the missing element. So if arr = [2, 4, 8, 10, 12, 14], output is 6, as 6 is missing.Using binary search, we can solve this problem. We will ... Read More

Advertisements