Assign Mice to Holes

There are N Mice and N holes placed in a straight line. Each hole can accommodate only 1 mouse. A mouse can stay at his position, move one step right from x to x + 1, or move one step left from x to x − 1. Any of these moves consume 1 minute. Assign […]

Coin Change Problem. Greedy Solution

Find min number of currency notes that we need to give for a given change. The following Video discusses the Greedy solution. If you want to master the art of Coding Interviews, join our online/offline course, click here…

Rectangles in a matrix

Given a character matrix in which some of the cells have alphabets written on them while other cells are empty (empty cells contains character ‘-‘ in them). For example consider the below matrix: A – – – B – – – C All characters are unique. Set character on all empty cells in such a […]

Flip all zeros to ones

Given a string of bits and a number k. In one flip, you can toggle k consecutive characters, how many flips are required to change the entire string to all ones. For example Input String: 0000110000 k: 3 OUTPUT: 4 Following are the four flips: FLIP-1: 1110110000 FLIP-2: 1110110111 FLIP-3: 1111000111 FLIP-4: 1111111111 If it is not possible […]