Friday, October 25, 2013

[Amazon Interview] Largest Rectangular area in a histogram

Find the largest rectangular are in a histogram where largest area can be made up of contiguous bars.
For simplicity, assume that all bars have same width of 1 unit.

Binary tree to doubly linked list

Convert a given linked list into doubly linked list in O(n) time.

Thursday, October 24, 2013

Coin Change

Given a value N, we want to make change for N cents and we have infinite supply of each of S={S1, S2...Sm}valued coins, how many ways we can make the change? The order of coins does not matter.

For example for N=4, and S={1,2,3}, there are four solutions: {1,1,1,1}, {1,1,2}, {2,2},{1,3}. So output should be 4.

[Microsoft] All subset of a set

Generate all subset of a given set. Example: Given set- {1,2,3}
Output: {}, {1}, {2}, {3},{1,2},{1,3},{2,3},{1,2,3}

[Amazon Interview] Queue using stack

Implement a queue using two stacks.

[Inmobi Interview] String: Replace space with %20

Write a method to replace all spaces in a string with %20.

Wednesday, October 23, 2013

Print all combination of balanced parenthesis

Write a function to generate all possible pair of parenthesis.

For example: if n=1 , then output: {}
                     if n=2, then output {}{}, {{}}