Sunday, September 2, 2012

Interview with Amazon

No need to explain about Amazon……….
They have asked three questions and I have failed that time to answer them correctly.
Q1.  Write a program for finding maximum sum path from a Tree from leaf to Root from Binary Tree (Not a BST).
Ex.                                                                   (10)
                                                               /                       \
                                                          (12)                       (15)
                                                       /           \                   /         \
                                                   (16)         (17)         (5)          (8)
Result should be:  17 – 12 – 10
Q2. This question is really tough, i have tried but not achieved till now, please try to understand if you will not then let me know i’ll give more explanations.
In a given array, each element represents steps to move forward, now you have to find minimum elements to cover whole array.
Ex:  Array : {1, 3, 5, 8, 9, 6,7,5,9,1,11}
So the array’s length is 11. Traverse the array
1 so from 1 pointer can go only one step.
So it will reach 3 now from 3 pointer can move 5, 8, 9
now 5 can move 5 to 8, 9, 6, 7, 5
and from 8 pointer can move 9,6, 7, 5, 9, 1,11 it covers whole array.
So minimum hops will be 1 -> 3 -> 8
So you have to write a program fro finding this optimum path.
Missed: If 0 (Zero) occurs pointer can’t move forward.
Q3. it was simplest one: write a program for finding pair of sum from a given array for given sum.
Ex: Array : {2,3,4,1,5,6,0}
Sum = 6;
Results should be: (2,4), (1,5), (6,0)
Solve these and post it….happy coding.

No comments:

Post a Comment

Interview With Amazon Chennai

Interview With Amazon Chennai Interview 1: Coding Problem: Q1. Write down a program which will sort the values at the level in...