An array of integer is given , both +ve and -ve. Find two elements whose sum is closest to zero.
Friday, December 13, 2013
Thursday, December 12, 2013
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.
The lot has 3 different kind of parking : regular, handicapped and compact.
Tuesday, December 10, 2013
[Fab.com] Occurence of first 1 in the sorted array of 0s and 1s
Find the ocuurence of first 1 in the array which contains 0s and 1s in the sorted manner.
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}
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.
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
Input String: A3B4C
Output: AAABBBBC
Thursday, December 5, 2013
[Microsoft]: Insertion in Sorted Circular linked list
Write a C function to insert an element in a sorted circular linked list.
Sunday, December 1, 2013
[Adobe]: Lowest Common Ancestor
Write a program to find lowest common ancestor in a Binary search tree.
[Goldman Sachs]: Check if a tree is BST or not
Write a program with time complexity O(n) and space complexity O(1) to check if a tree is BST or not.
Subscribe to:
Posts (Atom)