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.

Wednesday, December 11, 2013

[Fab.com] Design a car parking lot.

Design a car parking lot. Tell about all the classes and functions. It should be able to say full, empty, normal.
The lot has 3 different kind of parking : regular, handicapped and compact.

[Fab.com] Power of 2

Write a function to check if it is a power of 2.

[Fab.com] Ugly number

Write a function to find n ugly numbers.

Tuesday, December 10, 2013

Monday, December 9, 2013

[Fab Interview] Segregate 0s and 1s

Given an array of 0s and 1s in random order. Segregate 0s on the left side and 1s on the right side.
Traverse the array only once.

Input Array: {0,1,0,1,1,1}
Output Array: {0,0,1,1,1,1}

[Amazon] Subarray with sum 0

Given an array of integers with positive and negative numbers. Find if there exist a subarray with sum 0. If any, print the starting index, otherwise print 0.

Example:  Input Array: {1,2, 3, -1, 4, -3, 2}
               Subarray is: {-1, 4, -3} which gives sum as 0.


[Amazon Interview]: Append and delete node in unordered DLL

Append and delete a node in an unordered DLL.

[Amazon]: Decode a run length encoded String

Decode a run length encoded string. Don't use extra space. Time Complexity- O(n)
Input String: A3B4C
Output: AAABBBBC

Thursday, December 5, 2013

Sunday, December 1, 2013