In each round they ask me why I want to join amazon, why I am leaving my previous company with such a short span(around 2.5 months) and project stuff.

Interviewers were quite friendly. They would explain you till the point you fully don’t understand. And even while discussing approach and solving, they would clear your doubts if any.

**Online Test on InterviewStreet**

1. Given 2 string , find whether 2nd is sub-string of 1st or not. (it would be great if you solve with KMP)

2. Given 2 rectangles , find whether they are overlapping or not.

3. Given list of coins with various values (unlimited coins of each type) , find how many ways you can make a given value. (DP was expected.) Since it was not guaranteed that coin of value 1 would be present , we have to return -1 if the given value is not possible.

All rounds on same day.

**1st f2f:**

First I was ask to introduce myself and give a brief over my projects. Latter he ask me to explain any one of my project and the hardest task I have done.

We have used infix to post ix and postfix evaluation for our generic search expression’s evaluation. Here we had a lot of discussion on why conversation from infix to post-fix was needed and all.

1. Given a String s and int r , first fill each character row wise and print column wise.

for e.g. String s = “abcdefgh” and r = 3

so filling column wise would give :

a d g

b e h

c f

and final ans would be adgbehcf.

he just wanted the exact output. Internally how we handle string was not concern.

2. given a string or say number .. for e.g. 134 now with each number , as per mobile’s keypad , some letters would be associated.

here 1 – > abc , 3->ghi, 4 ->jkl . So we should print all the permutation such that we take 1 character from each of the number.

input number can be of any arbitrary length.

lets say each digit has m numbers associated , then for the input of length n , we need to generate n^m possible strings.

Took a map of

Interviewer seemed quite impressed here.

**2nd f2f**

1. Find integer part of sqrt of given number. Initially I gave o(root(n)) solution. Later solved with binary search(O(logn)).

2. Given an array of integers. replace each number with next higher number on its right side , which is nearer.(if not present than keep it as it is.)

for e.g. input – > 3 4 6 1

output->4 6 6 1

I suggested we can traverse from right side , we will take extra array (o(n) space complexity here) and in that array , we would store index of next higher nearer number.

so it would be like

if (a[i] < a[i+1] then store i+1; else traverse using index stored in auxiliary array

Since we needed extra space to store indexes, he asked that the input is array of a structure which has number and higher Index, 2 fields. So that we don't need extra space and extra traversal.

class Node { int val; int higher; }

He was very interested to see how i keep track of indexes and how i traverse between them. It is o(n) with o(1) space complexity. (when we have a[i]>a[i+1] we don't do linear search , but we jump using the indexes, so its not o(n^2)) It was hard to convince him on complexity.

3. given a binary tree. connect all the node at the same level. each node would have left,right and nextSibling pointers. we need to fill nextSibling.

solved with level order traversal . Similar to BFS on tree with queue. Only approach was needed, no code for this one.

**3rd f2f (Hiring Manager)**

1. It was a design question. You have to design a game. it has different types of monsters and different weapons. hero would shoot monster. each monster would have some initial health. Each weapon would do some predefined damage to monster. when its health gets 0, monster would die/disappear. and there would be multiple levels. based on level, monster and their behavior would change.

2. Given a read only linked list with next and random pointer , clone the list. I told him that i know the solution and explained him the approach. It was with the use of hashmap and takes o(N) extra space. Then he ask me whether I know a o(1) space solution, since I didn't knew, i was told to solve this. With this , he told that I can modify link list.

Initially I struggled, but with his help, in the end came up with working code. He was looking fine with implementation.

Here I ask about the work culture and the process being followed at amazon.I ask lot of questions regarding tools and technology they use. Since I had work on scrum model , it was quite interesting. He seemed to be impressed here.

**4th f2f(Dev Manager)**

1. Given 2 sorted linked list , merge them into single sorted list. Change the pointers, don't copy data. (same as merge part of mergesort on SLL)

2. Given binary tree, connect all the nodes which are in same column. 1 caveat was that same 1 node can have 2 parents. Here as in example, node 7 is being pointed by 2 and 6.

Solved it using level order traversal. Used a Map

He deed the dry run with example and code and he was OK with final approach.

1 / \ 2 6 / \ / \ 3 7 8 / / 4 12 / \ \ 5 9 13 \ \ 10 14 \ 11

Finally after two days, I got call from HR that I am selected ðŸ™‚

Many Many congratulations to the Priyank. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.