Amazon Interview | Set 87 (For SDE)
I recently cleared the Amazon SDE position. Through out my preparation GeeksforGeeks played great role, this is the only site which i referred/followed more than 90% of the time during preparation phase.
Please find my experience with amazon below.
1 Written test
1) Given a array of number find the next greater no in the right of each element
Example- Input 12 15 22 09 07 02 18 23 27
Output 15 22 27 18 18 18 23 27 -12) Given a link list and input int K, reverse the link list in K size slots
Example Input 12--> 13--> 3--> 20--> 55--> 87--> 20--> 77--> 90 Lets k =3 Output 3--> 13->12--> 87--> 55--> 20--> 90--> 77--> 20
3) Given tree and input int K, Print the nodes that are k distance way from leaf.
Input is below tree and k = 2

Output-2, 5, 4
2. First F2F round (DS and Algo)
Two interviewer was there in panel, Only one was asking question other was only observing, He was noting down all the conversation happening between us and noticing approach and solution provided by me. This was common in all the interview rounds.
1) Given a infinite string of O’s and 1’s respectively. You need to find the transition point from 0 to 1.
I gave the native solution in O(n). He told to optimize more. Direct binary search can’t be applied on it because string was infinite and length of string was not given.
I told that i will divide the string in 10 size slots it will reduce complexity. Still he told to optimize more. I told i will increase the slot size in power of 2 like 2,4,8,16,32. he was satisfied with that.
He again complicate it by adding that now my string contain 0, 1, 2 in sorted order. You need to find transition point from 0 to 1 and 1 to 2. i provided the approach.
After that told this time i want to make it generic. String can contain 0 to n(input) number find all the transition point. I solved it, he was satisfy with approach and told me write code for it.
2) Find common elements out of two sorted array
3. Second F2F(DS and Algo)
1) It was bit difficult for me to crack, She stated asking from java cloning, which was my weak area. Given a class which contain string Name and reference to person friend, clearly shown below.
Class A {
A(String str, Person P { //Constructor
this. name = str;
this.friend= P ;
}
// override
Clone() {
// code for this function was expected from me
// which can produce the deep copy
}
}Suppose A–>B–>C–>D means A is friend of B, who is friend of C and so on..
Calling once the Clone method will clone the whole friend list like
A’–>B’–>C’–>D’ (there A’ is the clone of A).
Cracking this was really tough for me, because i was not familiar with these question.
2) How to find the last nth element from singly link list, its was very easy for me.
Solved in 2 min and wrote the code quickly.
3) Given a sorted array of number, value K and value X, find the K nearest number to the value
Example: Input 12 16 22 30 35 39 42 45 48 50 53 55 56 K = 4 X = 35
Output 22 30 39 42
Interviewer was running out of time because 1st question took huge time. So she told to tell only the approach, code was not expected.
4. Third F2F (Bar raiser)
5. Forth f2f round(OOPS, design pattern and OS fundamental)
6. Fifth f2f (Hiring manager)
Message for all :-
Amazon expect accurate and precise code with less complexity. So discuss first with your interviewer the approach. Don’t jump into code.
Even if you don’t know the right answer, keep on discussing various possibilities to solve the question and try crack that problem with different angle. Practice more and more verity of questions.
Many many congratulations to the author. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course. In case you are prepared, test your skills using TCS, Wipro, Amazon. Google , E-Litmus and Microsoft Test Serieses.



