Recently Amazon India visited our campus for 2 months internship. There were three rounds
2 online coding questions + 20 MCQ
The MCQ questions were mainly 6-7 questions on data structures, 7-8 C language output programs, 4-5 questions on general aptitude, Probability, Permutation and Combinations.
The two questions were:
a. Given a set of intervals, you have to group the overlapping intervals and display all the intervals in non decreasing order.
Tip: Although this is a very easy question and can be found on many online portals, just remember that the given input is in the form of a string and it needs to be parsed carefully.
For this, instead of converting the string into integers, you could use something like
//store a and b as you wish to
b. Given a set of integers, negative as well as non negative, You need to rearrange them such that negative and non negative integers at alternate positions.
Constraints: order of all the negative and nonnegative integers must be the same as before if there are more negative integers, the integers in excess should occur at the end of the array and same goes for the non negative integers in case they are more in number.
Again, for the input, you can use the above mentioned technique.
About 20 out of 150 students were selected after this round for Personal Interviews.
Following are the interview experiences of two of us.
1. Given a binary tree having 3 pointers, left, right and sibling out of which all the left and the right child pointers are already filled, you need to fill the sibling pointers with the addresses of the next node on the same level. If it is the last node of a level, fill NULL.
I first told him an approach using a level order traversal with a queue. Then he asked me to do it without a queue using recursion. I told him the approach and when he was satisfied, he asked me to write a code on paper with all the corner cases covered.
2. Given an array of size 2n+1 where n integers repeat two times and one integer occured only once, Find that integer. I told him by using XOR. then he changed the question to
Given an array of size 2n+2 where n integers repeat 2 times and 2 integers come only once. Find both of them. This can also be done using XOR. You can find the solution in the arrays section of Geeks for Geeks
3. Given any binary tree in which all the leaves had their left and right pointers connected in a doubly linked list from left to right instead of pointing to NULL. Also, the leftmost leaf’s left pointer pointed to that node itself and the rightmost leaf’s right pointer pointed to that leaf itself and if there was an internal node with no left or right child, that particular pointer will point to that node itself.
You need to find the Inorder Traversal of the tree.
Once I told him the approach, he again asked me to write a code on paper.
4. He asked me about the data structures I knew and then started asking questions on Graphs. How we represent them?
which is better Adjacency matrix or List?
Then he gave some situations and asked me which of the two implementations should be used.
1. He asked me in detail about my projects for about 15 minutes.
2. Then he asked me about the subjects I had studied in 3rd and 4th semesters.
I forgot what all subjects I had studied 😀 😀 😀
The first subject that came out of my mouth after a lot of thinking was Unix Linux Programming. Then he asked me to write all the commands I knew in 5 minutes. I listed almost 20. He asked me the functions of a few of them and differences between some of them.
3. Finally he asked me a question on binary trees which was pretty simple.
Replace the data of every node of a Binary Search Tree with the sum of all the nodes greater than it.
I gave him the approach using reverse inorder traversal. He then asked me to write a code on paper. I had used pointers in the code. He then asked me to write a code that did not use pointers, static variables or global variables.
I wrote that. Finally he appeared satisfied.
1. Given a singly linked list and an integer k, I had to write code to reverse the list in pairs of k handling all base cases as well.
eg. 1->2->3->4->5->6->7->8 k=3
She actually tried my code on a number of base cases trying to find bugs 😛
2. Given 2 arrays one of size n and another of size (n+k) but having k values filled, I was asked to merge the two into the second array without using any extra space. I quickly gave her the logic and we moved on to the next question.
3. Given a string of characters, find the index of the first repeating character in the string.
o/p: 0 (as ‘a’ came initially before ‘b’ did, though both are repeated twice).
Again error free code was required.
4. She then asked me questions on the research project I was currently working on. This went on for another 10-15 minutes.
1. This round started with questions on my research project. Then he asked me which data structures I liked. We had a long discussion on heaps and the associated time complexities.
2. Given a binary tree, any node in the tree and an integer k, print all the nodes at a distance k away from the given node.
Mind you, the node may be above or below. We first discussed on an approach and after he was satisfied with my explanation, he asked for error-free code.
3. Given an integer n, how many BST’s can you make with n no of nodes?
I told him about catalan number and the direct formula – 2^n – n. But he wanted a derivation, so I built-up a recurrence and showed him the DP to evaluate it.
4. Given n people, you are told all pairs of people who belong to the same country. You are to tell the number of pairs of people who do not belong to the same country,
I expressed it as a graph and applied dfs to get number of connected components and size of each. Then it was a simple formula over no of components.
After this he started discussing the life at Amazon, what the company expects from you and what you should expect to do at the company.
If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.