Arnab Chakraborty has Published 4452 Articles

C++ program to find maximum possible value of XORed sum

Arnab Chakraborty

Arnab Chakraborty

Updated on 03-Mar-2022 06:03:28

95 Views

Suppose we have an array A with N elements and another value K. For an integer X in range 0 to K, let f(X) = (X xor A[1]) + (X xor A[2]) + ... + (X xor A[N]). We have to find the maximum possible value of f.So, if the ... Read More

C++ program to find minimum number of steps needed to move from start to end

Arnab Chakraborty

Arnab Chakraborty

Updated on 03-Mar-2022 06:02:02

666 Views

Suppose we have a coordinate (x, y). On a 2D grid, a robot is at (0, 0) position and want to reach (x, y). It can move up, down, left or right or stay at current cell. It wants to reach destination with as minimum as possible commands. We have ... Read More

C++ program to count at least how many operations needed for given conditions

Arnab Chakraborty

Arnab Chakraborty

Updated on 03-Mar-2022 06:00:04

136 Views

Suppose we have an array A with N elements. In each operation, we pick an element and increase or decrease it by 1. We have to find at least how many operations are needed to satisfy following conditions −For every i in range 1 to n, the sum of the ... Read More

C++ program to find permutation for which sum of adjacent elements sort is same as given array

Arnab Chakraborty

Arnab Chakraborty

Updated on 03-Mar-2022 05:58:50

162 Views

Suppose we have an array A with n elements. A function F(p) is a sorted array of sums of adjacent elements in p. So F(p) = sort([p1 + p2, p2 + p3, ... pn-1 + pn]). We have a permutation represented in A. We have to find the different permutation ... Read More

C++ program to find smallest and largest number of children in game before start

Arnab Chakraborty

Arnab Chakraborty

Updated on 03-Mar-2022 05:57:06

107 Views

Suppose we have an array A with K number of elements. Consider, in a game there are N players and a game master is there. This game has K rounds. In ith round game master announces to form groups with A[i] number of children. Then the remaining children form as ... Read More

C++ program to find number of l-r pairs for which XORed results same as summation

Arnab Chakraborty

Arnab Chakraborty

Updated on 03-Mar-2022 05:53:54

87 Views

Suppose we have an array A with N elements. We have to find the number of pairs of integers l and r that satisfies A[l] XOR A[l+1] XOR ... XOR A[r-1] XOR A[r] = A[l] + A[l+1] + ... A[r].So, if the input is like A = [2, 5, 4, ... Read More

C++ program to find how many characters should be rearranged to order string in sorted form

Arnab Chakraborty

Arnab Chakraborty

Updated on 03-Mar-2022 05:53:45

131 Views

Suppose we have a string S with n characters. S contains lowercase letters only. We must select a number k in range 0 to n, then select k characters from S and permute them in any order. In this process, the remaining characters will remain unchanged. We perform this whole ... Read More

C++ program to count how many minutes we have to wait to meet at least one swimmer

Arnab Chakraborty

Arnab Chakraborty

Updated on 03-Mar-2022 05:50:08

166 Views

Suppose we have four numbers p, a, b and c. There is a pool and three swimmers are there. They take a, b and c minutes to cross the pool and come back, respectively. So the first swimmer will be at the left side of pool after 0, a, 2a, ... Read More

C++ program to find sum of all cells lighten by the lamps

Arnab Chakraborty

Arnab Chakraborty

Updated on 03-Mar-2022 05:49:46

98 Views

Suppose we have a grid with H rows and W columns. Where each square is tidy or untidy. We can place lamps on zero or more more tidy squares in this grid. A lamp can lighten the cells in each of the four directions - up, down, left, and right ... Read More

C++ program to check we can rearrange array in such a way that given formula returns m or not

Arnab Chakraborty

Arnab Chakraborty

Updated on 03-Mar-2022 05:43:20

69 Views

Suppose we have an array A with n elements and another number m. We have to check whether we can rearrange the array in such a way that$$\mathrm{\sum_{i=1}^{n} \sum_{j=1}^{n}\frac{A[j]}{j} = m}$$There will be no rounding in A[j]/j operation.So, if the input is like A = [2, 5, 1]; m = ... Read More

Advertisements