Saturday, May 24, 2014

Friday, December 13, 2013

[Fab.com] Two elements whose sum is closest to zero

An array of integer is given , both +ve and -ve. Find two elements whose sum is closest to zero.

Thursday, December 12, 2013

[Microsoft]100 bulbs puzzles


Microsoft] Print last 10 lines

Given some text lines in a string, each line is separated by '\n' characters. print the last 10 lines. If no of lines is less than 10 , then print all the lines.

Deepest left leaf mode in a binary tree

Given a binary tree, find the deepest leaf node which is left child of its parent.

[Fab.com] Find the celebrity

Given a function know(A,B) which returns true if A knows B , otherwise false. Now there is one celebrity who is known to everyone and who does not know anyone. Given an array , find the celebrity in less than linear time.

[Amazon] Find an element in array whose element differ by 1

Given an array in which two elements differ by +1 or -1. Find an element k in such an array in less than linear time.