In a prison, there are N cells. The positions of the cells are given in an array. The Jailer has to place all the prisoners in the cells in an ordered manner ...read more
Binary Search
15 postsGiven an infinite stream of integers, find the k’th largest element at any point of time. It may be assumed that 1 <= k <= n. Example: Input: stream[] = {10, 20, ...read more
Given three arrays start[], duration[], amount[] of length N. A person can make money of amount[i] working for the time period [start[i], start[i]+duration[i]] on task i. Maximum amount of money a person ...read more
You have to paint n boards of length {L1, L2, L3,…,Ln-1}. There are k painters available and each painter takes t time to paint 1 unit of board. You have to get ...read more
There is given a sum and you have to find whether this sum is resultant of summation of first n natural numbers or not. If it is summation of first n natural ...read more
You have a total of n coins and you want to arrange the coins in staircase shape, where every i-th row must have exactly i coins. You want to find the total ...read more
Mithlesh has ‘N’ buckets each consisting of some fruits. Mithlesh wants to eat at least ‘M’ fruits and so, he decided to set a marker (integer) as maximum as possible such that ...read more
You are given a m*n row wise sorted matrix. The task is to find the common element in all rows of given matrix. Examples: Input : mat[3][4]={{1,3,5,6}, {3,4,7,8}, {1,2,3,4}} Output: 3 Input ...read more
Given an array consisting of integers in range 1 to n consisting of only one duplicate element. Find out the duplicate element in O(logN) time. Examples: Input : 6 1 1 2 ...read more
Given a sorted array and a value x, we need to find floor and ceil value of x in the array using improved binary search technique. Floor value is the largest element ...read more