eyeonu.imtiyaz
- 9
0of 0 votes
AnswersGiven two node values for a tree, find LCA. Consider edge cases - (1) If there exists only one value in the tree, return null. (2) If none of the values exist in the tree, return null. (2) Handle ancestors for duplicate values like -
- eyeonu.imtiyaz on November 01, 2012 in United States Edit | Report Duplicate | Flag
20
/ \
10 50
/ \ / \
10 17 40 60
/ \
5 15
So for above tree if values 5 and 17 are given, there LCA is the upper 10 and not the lower. You can exemplify something I bet :-)
Amazon Software Engineer / Developer - 7
0of 0 votes
AnswersGiven a sorted array of size n implemented as ring buffer, so that when array has reached (n-1) index, it will be overwritten from 0th index and likewise it will continue. Given any number, find its index in the array in less than linear time. Interviewer asked to consider the edge cases which I could not quite understand during the interview. I told, the edge cases would be no-element array, array with one element and such.
- eyeonu.imtiyaz on November 01, 2012 in United States Edit | Report Duplicate | Flag
Amazon Software Engineer / Developer - 6
0of 0 votes
AnswersI will try to state the question. We all know mobile phone's keypad where "2" is mapped to ABC, "3" to DEF and so on. Given any sequence of integers, find all the (matching) combinations in your phone book.
- eyeonu.imtiyaz on November 01, 2012 in United States Edit | Report Duplicate | Flag
Amazon Software Engineer / Developer Data Structures - 4
0of 0 votes
Answers(screening round)
- eyeonu.imtiyaz on October 30, 2012 in United States Edit | Report Duplicate | Flag
Implement atoi. What would be your approach converting for string to hex.
Amazon Software Engineer / Developer C - 6
0of 0 votes
Answers(screening round)
- eyeonu.imtiyaz on October 30, 2012 in United States Edit | Report Duplicate | Flag
Given two sorted arrays, merge them into result array with sorting. Time and Space Complexity.
Amazon Software Engineer / Developer Sorting
Lets consider for allowing duplicates, 15 is in the right position. (Even the interviewer was stumped when he was creating a tree with duplicates for demonstration)
- eyeonu.imtiyaz on November 02, 2012 Edit | Flag View ReplyI understand that the 'else if ' is checking for values less than rootnode. No problems. Also, the recursion will terminate if(root.data > value1 && root.data < value2). Again,
if(root.data < value1 && root.data > value2)
10 and 17 are children of 10 and 40 and 60 are children of 50 :-)
- eyeonu.imtiyaz on November 01, 2012 Edit | Flag View Reply@ASU
- eyeonu.imtiyaz on November 01, 2012 Edit | Flag View Reply@Bin - There is already a thread to handle spaces, negative signs and buffer overflow.
- eyeonu.imtiyaz on October 31, 2012 Edit | Flag View Reply
@The Artist - say the array is of fixed size n. When you are done filling the array from 0 to n-1, the next insertion would take place at the zeroth position. For example, you have array like this -
- eyeonu.imtiyaz on November 02, 2012 Edit | Flag View ReplyValues 1 2 3 4 5 6 7 8 9 10
Array Index 0 1 2 3 4 5 6 7 8 9
Now, if values 11, 12 and 13 are inserted, your array would like like -
Values 11 12 13 4 5 6 7 8 9 10
Array Index 0 1 2 3 4 5 6 7 8 9
That being said, the answer to your first question is yes, the least element can occur at any position. For the question about traversal, I mentioned it that we have to keep it less than n, that is, the linear time. So, traversal should be avoided and as CodeSpace mentioned, binary search is the solution with some modification.