Amazon's technical test consisted of an objective section of 20 questions and a subjective section in which you need to write working code. The test was conducted on InterviewStreet. Following programming questions were asked at the various IITs in 2012:
IIT-B
1) Given Preorder traversal of a BST, implement a function to find its Postorder traversal.
2) Given some set of strings, print all the strings that are anagrams adjacent to each other.
IIT-R
1) Given a linked list with each node containing a character in A-Z, rearrange the list so that all the vowels are at the beginning and consonants are at the end.
2) Print all the unique triplets (a, b, c) in an array from which we can form a triangle whose sides are of lengths a, b, c.
IIT-KGP
1) You are given a tree with each node having an integer element. For each leaf-node, sum of integer elements on path from root to leaf is computed. Find the leaf node with a) maximum sum, b) minimum sum
Follow up: Print the path with min/max root to leaf path sum
2) Given an array of integers, find 2 elements having minimum difference in their absolute values.
IIT-K
1) You are given a linked list, and you have to swap every 2 consecutive nodes with each other.
eg. 1->2->3->4->5 will become 2->1->4->3->5
2) You are given an array of string and you have to print all the pairs which are anagram of each other. You should ignore the case of the characters in strings while checking for anagrams, so "Cat" and "Act" are anagrams of each other.
IIT-D
1) Given an array of +ve integers, join these integers in a way to maximize the resulting number formed.
Ex: [884 88] -> 88884
[20 19 90] -> 902019
[909 90] -> 90990
2) Given a tree and a value x, check if there exists a path in the tree with nodes that sum up to x.
Note: The path has to start at any node and go down the tree.
So, other than reconstructing the tree, how would one go about finding the postorder traversal (IIT-B)?
ReplyDeleteThis comment has been removed by the author.
Delete#include
Delete#include
print(int preOrder[],int start,int end)
{
int index=-1,i;
if(start>end)
return;
if(start==end)
printf("%d",preOrder[start]);
else
{
for(i=start;i<=end;i++)
if(preOrder[i]>preOrder[start])
{
index=i;
break;
}
if(start+1<index)
print(preOrder,start+1,index-1);
if(index!=-1)
print(preOrder,index,end);
else
print(preOrder,start+1,end);
printf("%d",preOrder[start]);
}
}
int main()
{
int preOrder[]={5,3,2,4,7,6,8};
print(preOrder,0,6);
return 0;
}
@Upik Well I gave it a thought, but reconstruction and then postorder was all I could think of during the test. Do u have some better idea?
ReplyDelete