Arnab Chakraborty has Published 4293 Articles

Find minimum shift for longest common prefix in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Dec-2019 10:32:58

517 Views

Consider we have two strings A and B. The length of A and B are same. In a single shift we can rotate the string B one element. We have to find minimum required shift to get common prefix of maximum length from A and B. So if A = ... Read More

Find all elements in array which have at-least two greater elements in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Dec-2019 10:30:50

358 Views

Suppose, we have an array of n numbers. We have to find all elements in array, which have at least two greater elements. If the array is like A = [2, 8, 7, 1, 5], then the result will be [2, 1, 5]To solve this, we will find second max ... Read More

Find minimum cost to buy all books in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Dec-2019 10:28:22

278 Views

Suppose we have an array of n elements. These are the ratings of them. Find the minimum cost to buy all books, with the following condition −Cost of each book would be at-least 1 dollarA book has higher cost than an adjacent (left or right) if rating is more than ... Read More

Find all combinations of k-bit numbers with n bits set where 1 <= n <= k in sorted order in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Dec-2019 10:26:54

429 Views

Suppose we have a number k. Find all possible combinations of k- bit numbers with n set-bits where 1

Find minimum area of rectangle with given set of coordinates in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Dec-2019 10:25:32

407 Views

Suppose we have an array of some points in XY plane. We have to find the minimum area of rectangle that can be formed from these points. The side of the rectangle should be parallel to the X and Y axes. If we cannot form the rectangle, then return 0. ... Read More

Find a time for which angle between hour and minute hands is given theta in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Dec-2019 10:24:37

146 Views

Suppose we have one theta, or angle value. We have to find one time in hh:mm format, that creates the angle by the hour and minute hands. Suppose the angle is 90°, then the result can be 3:00.As there are 12 hours, so there are 12 possibilities for hours and ... Read More

Find maximum vertical sum in binary tree in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Dec-2019 10:23:16

138 Views

Suppose we have a binary tree. The task is to print maximum of the sum of all nodes in the vertical order traversal. So if the tree is like below −The vertical order traversal is like −4 2 1 + 5 + 6 = 12 3 + 8 = 11 ... Read More

Find maximum value of x such that n! % (k^x) = 0 in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Dec-2019 10:19:43

195 Views

Suppose we have two integers n and k. We have to find the maximum value of x, such that n! mod (k^x) = 0. So when n = 5, and k = 2, then output will be 3. As n! = 120, now for different values of x, it will ... Read More

Find a permutation such that number of indices for which gcd(p[i], i) > 1 is exactly K in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Dec-2019 10:18:01

271 Views

Suppose we have two integers N and K. We have to find a permutation of integers from the range [1 to N] such that the number of indices (1 – base indexing) where gcd(P[i], i) > 1 is exactly K. So if N = 4 and K = 3, then ... Read More

Find maximum power of a number that divides a factorial in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Dec-2019 10:16:30

257 Views

Suppose we have two numbers n and fact. We have to find the largest power of n, that divides fact! (factorial of fact). So if fact = 5, and n = 2, then output will be 3. So 5! = 120, and this is divisible by 2^3 = 8.Here we ... Read More

Advertisements