Reply the solutions if you have any so that we can discuss...
Given an array of n elements (containing only positive numbers) and sum, X. Find the first two elements in the array that sum upto X
eg: Array of elements - {2, 3,1000, 200, 51, 88, 29, 49, 65, 40, 98, 12, 3}
Sum - 100.
The answer for the above sample is 51, 49.
There are other possiblities also, but the first two numbers summing upto the given sum, 100 should be taken.
How will you do this with minimal space and time complexities?
Question 2
Given two nodes of a binary tree (implemented in a linked list without a parent pointer) and a head pointer, find out the common ancestor of the two nodes with minimal space and time complexities...
Not necessary for an perfect answer...any answer will be appreciated...
Many posts will refine the solution more. Thanks.
Question 3
Given two nodes of a Binary Search Tree (implemented using linked list without a parent pointer) and the head pointer, find out the common ancestor of the two nodes with minimal space and time complexities...
All answers will be greatly appreciated...
Question 4
This was asked in an interview with GOOGLE.
Given an array (dont consider the data type of the element) of 2n elements with first n integer elements and next n character elements.
i1 i2 i3 ....in c1 c2 c3 ....cn
Write an in-place algorithm to rearrange these elements in the following order.
i1 c1 i2 c2 i3 c3....incn.
in-place algorithm means that the memory used in the algorithm other than the input array should not be dependent on the size of the input.... Also keep this in mind -- Time and space complexity.


