Amazon
Amazon
1 Set 1 29
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
2 Set 2 32
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3 Set 3 34
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4 Set 4 36
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
5 Set 5 38
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
6 Set 6 40
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
7 Set 7 42
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
8 Set 8 44
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
9 Set 9 (Answers) 48
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
10 Set 9 50
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
11 Set 10 55
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
12 Set 11 58
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
13 Set 12 60
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
1
Contents
14 Set 13 62
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
15 Set 14 64
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
16 Set 15 66
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
17 Set 16 68
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
18 Set 17 70
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
19 Set 18 72
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
20 Set 19 74
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
21 Set 20 76
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
22 Set 21 79
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
23 Set 22 83
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
24 Set 23 86
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
25 Set 24 89
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
26 Set 25 92
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
27 Set 26 95
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
28 Set 27 97
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
29 Set 28 100
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
30 Set 29 103
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
2
Contents
31 Set 30 106
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
32 Set 31 109
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
33 Set 32 111
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
34 Set 33 115
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
35 Set 34 118
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
36 Set 35 121
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
37 Set 36 123
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
38 Set 37 125
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
3
Contents
4
Contents
77 Set 74 211
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
81 Set 78 219
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
5
Contents
83 Set 80 224
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
86 Set 83 230
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
87 Set 84 232
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
88 Set 85 234
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
89 Set 86 237
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
91 Set 88 244
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
92 Set 89 246
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
93 Set 90 249
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
94 Set 91 251
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
95 Set 93 253
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
6
Contents
7
Contents
8
Contents
9
Contents
10
Contents
11
Contents
12
Contents
13
Contents
14
Contents
251 Set 248 (4.8 Yrs Experience for SDE II) 626
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 627
15
Contents
16
Contents
17
Contents
18
Contents
19
Contents
20
Contents
21
Contents
22
Contents
23
Contents
24
Contents
25
Contents
26
Contents
447 Amazon Interview Experience (On Campus for 2 Month Internship) 1063
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1063
451 Amazon QA role & Support Engineer Intern interview experience 1075
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1076
27
Contents
28
Chapter 1
Set 1
29
Chapter 1. Set 1
30
Chapter 1. Set 1
Write a function in order to make the robots meet each other. Robots will be executing the
same copy of this function.
HIRED!! �
Tips / Advice:
I. Each time you write a code, check for the edge cases.
II. Do not assume anything. Keep asking questions if there are any doubts.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview/
31
Chapter 2
Set 2
32
Chapter 2. Set 2
can keep on putting slabs on each other. Find the maximum stack possible which you can
create out of the given slabs.
Question 2: The above question was raised to 3 dimensions.
Question 3: The above question was then raised to k dimensions.
Questions : Then there were many questions asked on compilers and dynamic memory
allocation.
Interview Round 3(50-60 Minutes):
Technical Interview
Question 1: You are given pairs of numbers. In a pair the first number is smaller with
respect to the second number. Suppose you have two sets (a, b) and (c, d), the second set
can follow the first set if b<c.So you can form a long chain in the similar fashion. Find the
longest chain which can be formed.
Question 2: Find the longest increasing subsequence in O(nlogn). Proof and full code
was required.
Question 3: You are given a linked list and an integer k. Reverse every consecutive k nodes
of the given linked list.
Question 4: You are given an array. For every element you have to replace it with the
closest number on the right side which is greater than the element itself.
Interview Round 4:
The team was highly impressed so they cancelled my 4th round � for others who appeared
for the 4th round, it was atleast an hour long.
HIRED!! �
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-2/
33
Chapter 3
Set 3
34
Chapter 3. Set 3
Question 1: Delete nth node from end of a linked list in a single scan.
Question 2: In a linked list, in addition to the next ptr, a random ptr is also present.
Clone the linked list.
Did it in O(n) but by modifying the linked list and then restoring it. Was asked to do it
without making any modifications in the original list. Did that in O(n^2)
Question 3: Two nodes of a BST are given. Print the path from 1st node to the 2nd node.
You are also provided the parent pointers in addition to normal left and right pointers.
Interview Round 3(1 hour)
Question 1: An array of n integers is there in which the range of elements is n, i.e., the
difference between maximum and minimum number is n. Find the repeating numbers.
Question 2: An extension of Question 1. Was asked to find number of times each number
is repeated.
Question 3: There are n frames of m data element each. The data element in each frame
is arranged in increasing order. You are provided m*n space in which you have to arrange
all data in increasing order.
My 1st solution was to use merge sort. He modified the question as only O(n) space is there
and you need to send data in increasing order as fast as you can.
My 2nd solution was to use min heap and construct it with the 1st element of all n frames.
Min heap also contains extra field which signifies the frame number of data elements. This
data structure can do the needful.
Interview Round 4(1 hour)
Question 1: Replace each element of an array with its greatest next integer in O(n).
I couldn’t do it. I tried but it didn’t click. Not expected when you are in your last round.
Question 2: Reverse every k nodes of a linked list.
Well did that but was not finally selected……. �
This article is compiled by Vinay Khetan. We will be soon publishing Vinay’s Yahoo
and Microsoft interviews as separate posts. Vinay was selected in Microsoft. Many Many
congratulations to Vinay for his selection.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-3/
35
Chapter 4
Set 4
36
Chapter 4. Set 4
Other questions were regarding Operating system like virtual memory etc.
Round 4:-
It was HR round. Questions related to project. Questions like why I should Hire you etc
were asked.
Result is still on wait.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-4-2/
37
Chapter 5
Set 5
38
Chapter 5. Set 5
Third round
1. So many HR like questions. Why Amazon, Why u want to leave, Why u dont want to
stay, what did you do to stay back, biggest challenge, worst mistake, etc etc.. blabbered
something.
2. Write a method that will test a function which merges 2 sorted linked lists.
3. Design a system, which can convert books from one format to another
Fourth Round
Only one design question: Design a email client.
After 4 days and lot of anticipation, I got a mail saying I got rejected, Was wondering what
they exactly look for.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-4-3/
39
Chapter 6
Set 6
40
Chapter 6. Set 6
Source
https://www.geeksforgeeks.org/amazon-interview-2/
41
Chapter 7
Set 7
42
Chapter 7. Set 7
2) least common ancestor in a binary tree [Note : not binary search tree ] [30+ minutes]
I explained him with several methods and finally he was ok with and asked me to write the
code for and i did it. he checked my code for different test cases and finally he was ok with
it ..
Not even 5 minutes break i was asked to get ready for next face to face interview .
2nd face to face interview [1 hr 20 min ]
Short description about myself [2 min alone. just told mmy name and my most important
project for which i won ipad 2. dont tell too much. they just wanted to know a little about
u . inshort ur name and college. ]
1) zig zag traversal of a binary tree. [35+ min ].
Man i have studied this in geeksforgeeks and wrote him the code using recursion, which was
working perfectly. But he told me to use reduce the complexity by using any data structures.
I told him a logic using a stack and a queue. Another logic using 2 stacks . But he wanted
me to use only one data structures. I tried using a single queue and he to helped me a little
and finally he was ok with it .
2) A n*n matrix is given which is containing elements in which each row alone is sorted.
column is not sorted. I have to convert it into a single dimensional array which will hold all
the elements of the array in a sorted manner.
I told him many logics . actually he kept on adding constraints with whatever logic i told
him. Finally he gave me a hint and asked to use minheap property and finally he was
ok with it. I solved this question using lots of help with him. man i was in interview for
continuously more than 3 hours.
I am waiting for my result for next round. I will update if i go through the next rounds.
Overall it was a great experience with amazon and people in amazon are very smart minded.
Hope this is helpful to someone!
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/microsoft-interview-set-7-2/
43
Chapter 8
Set 8
44
Chapter 8. Set 8
45
Chapter 8. Set 8
This interview was with the hiring manager at Amazon. He first asked me a couple of HR
questions like Why Amazon? Why should we hire you? Projects, internships etc ..? How
would you handle a disagreement with your team mates? Etcetc …
Then he asked me a programming question.
Q: He drew a circle on the board and marked a few points on it. Named them X1, X2, X3
..
Then he said these are gas stations, and you have to find the correct gas station from where
a car should begin to loop in the circle such that it never runs out of gas before completing
a round. He then sat on the table.
(Sorry, but I will have to describe it in detail to tell you how it was put out to me.. and
off-course to bring in more clarity to the question itself.. )
Unclear about what I had to do exactly and what information was available, I asked him
back a few questions.
Why will car run out of gas after fuelling from lets say the first gas station?
He said each gas station has limited amount of gas (lets say X1) and after fueling from
this station it can run out of gas even before reaching the next station (anything could
happen, it may be able to cross the next gas station but run out later before completing
the round..). So I have to find a gas station the car should start the loop from such that
it never runs out of gas before completing the loop.
So can the car refuel at the next available gas station, if its able to make up to it?
Yes
Do we have the information about the amount of gas required to reach from one petrol
pump to another?
Yes
I made an assumption that the car tank was huge enough to fill as much gas as possible.
And then I drew two arrays, one holding the amount of gas each station had, and other the
amount of gas needed to go from this station to the next station..
Fuel Available: X1, X2, X3, X4, X5
Fuel Required to reach next station: Y1, Y2, Y3, Y4, Y5
He said ok, and asked me to go ahead.
I then took the difference (Y1-X1), (Y2-X2) ..and stored it in an array.. and then suddenly it
hit me that this became a simple problem of finding the maximum sum of a continuous
subarray within an array (circular). He liked my approach and asked me to program it. Did
it and showed him a dry run of the code I had written. He was ok with it.
(I felt good after the interview because in there I didn’t stumble at all ..)
Personal Interview 4
Q1: We have a huge file with braces ‘()’ [just one type..] Find if they are balanced .. (stacks
wouldn’t work here because you will probably run out of memory storing the stack ..) When
46
Chapter 8. Set 8
I gave him another solution, he asked me to do it using parallel processes. I told him to
elaborate more.. (to be honest I wasn’t familiar with parallel processes) .. Finally I told
him so ..and he asked me to think about it still ..
We discussed it for about 20 minutes. Not reaching anywhere he moved on to ask me the
next question.
Q2: Find the smallest substring which contains all the characters of the main string. Again
I dint have a solution to this. I gave him a O(n^2) approach. He asked me to think further
because the way I was approaching it was the way to go about it and I can make use of the
last sub-solution obtained to improve my complexity. Couldn’t think of anything, we finally
moved on to the third question.
Q3: given the numerator and denominator of a fraction, find the quotient and the remainder
without using divide and mod (‘/’, ’%’ )operators. This was simple. I did it. He then
asked to write the invariant of my solution which was denominator*quotient + remainder
= numerator.
He then asked me to think about the cases when either or both of numerator and denom-
inator were negative. We were almost out of time so he didn’t give me time to think and
concluded the interview. He wanted me write an invariant that was true regardless of the
input. Now that I think of it, I should have said |denominator|*quotient + remainder =
|numerator|
Flew back home in the night.
2 Days later the HR informed me that I didn’t make it in. �
This was probably the most difficult of all the interviews I have ever had.
Hope it helps some of you ..
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-8/
47
Chapter 9
Set 9 (Answers)
Telephonic Interview 1:
1) https://www.geeksforgeeks.org/find-the-row-with-maximum-number-1s/
2) https://www.geeksforgeeks.org/check-whether-two-strings-are-anagram-of-each-other/
3) https://www.geeksforgeeks.org/array-rotation/
Telephonic Interview 2:
3) Find the distance of every other point from P. Then use of max-heap of size K.
https://www.geeksforgeeks.org/k-largestor-smallest-elements-in-an-array/
48
Chapter 9. Set 9 (Answers)
3. Repeat step 2 till we have any set which has intersection with any other set. At the end,
we will have the solution. (Still not sure about optimality).
We can relate the solution with graphs: Remove some nodes so that remaining all the nodes
are isolated nodes.
Searching: To make searching efficient, we can build trie data structure using bits for every
set. So that we can find the intersections fasters.
Face-to-face Interview 2 (with a manager):
1) I tried for some time. Then the interviewer gave me the formula. The number is
1+ceil((N-W)/S) in all the cases.
For second part of question, simple solution is to find min in every window. But we can
optimize so that we can utilize previous results/previous min.
Bit optimal: I created a min-heap of W elements. But the heap contained indices of the
array elements, not the values inside the array itself. The indices were stored in heap as
per their values in the array. Then for a new window, search the heap linearly (heap was
in form of array), replace the old indices (which are no longer in the new window) with the
new indices, and adjust that index in the heap. After adjusting all the new indices, we will
have new min for the new window at the root. (Not sure whether the complexity brought
in to the solution is worth!)
Face-to-face Interview 3:
2) I gave a solution based on trie data structure using characters of the string. But he
suggested to build trie based on the string itself. However, I was not able to think in that
way.
3) Linear search. Binary search.
Source
https://www.geeksforgeeks.org/amazon-interview-set-9-answers/
49
Chapter 10
Set 9
50
Chapter 10. Set 9
class Node
{
Node left, right;
int data;
Node(intnewData)
{
left = right = null;
data = newData;
}
}
4) Swap adjacent nodes in the linked list. Change the links, not the data. Complete the
method.
Ex:1, 2, 3, 4
o/P: 2, 1, 4, 3
ex: 1,2,3,4,5
op: 2, 1, 4, 3, 5
class Node {
Node next;
int val;
}
51
Chapter 10. Set 9
xp: 20,22,34,49,91,110
OR
3,5,34,49,91,110
Complete the method.
static int lengthLIS(Vector<Integer> sequence) {}
Telephonic Interview 1:
1) A M x N matrix, filled with 0s and followed by 1s. Find the row which contains
minimum number of 0s. E.g.
0 0000 1
0 0 1 111
0 00 1 11
The answer is 2nd row. (Row index: 1)
2) Find whether given two strings are anagrams of each other.
3) Given an array of size N, move the first d elements to its last.
e.g. {1, 2, 3, 4, 5}, d=2
• output: {3, 4, 5, 1, 2}
Telephonic Interview 2:
1) Given a BST, find the node which contains the value which is equal to (or lowest
greater than) the input value.
2) Kadane’s algorithm for 1 dimensional array.
3) Given a point P and other N points in two dimensional space, find K points out of
the N points which are nearer to P.
Face-to-face Interview 1: (Hyderabad, Date: November 08, 2012)
1) Given a Singly Linked List which contains integers, bring odd values in the beginning
and even values at the end. The relative order of odd values, and that of even values should
be maintained as it is.
e.g. 34, 45, 78, 10, 33, 5
2) Given N sets of integers, remove some sets so that the remaining all sets are disjoint
with one another. Find the optimal solution so that the number of sets remaining at the
end is maximum.
Face-to-face Interview 2 (with a manager):
1) Given an array of size N, a window of size W slides over it by increment of slide S. If
the window reaches to the end, we should stop there. Find a formula in form of N, S, W so
52
Chapter 10. Set 9
that we can find the number of valid windows. Write a program to find minimum in every
window and print it. Optimize it.
e.g. {1,2,3,4,5}, W=2, S=1
first window: {1,2} min=1
second window(increment by S=1): {2,3}, min=2
…
last window: {4,5}, min=4
The array might not be sorted. I have taken sorted array for simplicity.
Face-to-face Interview 3:
1) Trim the Given BST by given min and max values. It means remove the nodes which
have values less than min or greater than max. Write iterative and recursive – both the
solutions.
2) Given an array of strings, find the string which is made up of maximum number of
other strings contained in the same array.
e.g. “rat”, ”cat”, “abc”, “xyz”, “abcxyz”, “ratcatabc”, “xyzcatratabc”
Answer: “xyzcatratabc”
“abcxyz” contains 2 other strings,
“ratcatabc” contains 3 other strings,
“xyzcatratabc” contains 4 other strings
3) Find integer value of sqrt(N). Do not use any library functions or any mathematical
solution.
Face-to-face Interview 4 (with the manager of the unit of opening):
1) Given a 2-dimensional array of integers, find the value 1 in the array, and set all those
rows, and columns to 1, which contains one of the values as 1.
2) Suppose you are working in companies like naukri.com. You need to collect email Ids
and contact numbers of all the Software Engineers aged between 25 to 40, in India. How
will you do that?
3) Suppose a person of the age of your grandfather works on computer. He knows little
about the computer. And he complains that it was working fine, but for last 2 days, it has
become very slow. How will you solve it? What could be the reasons?
4) Design an IVR system for a Restaurant in which customers can book their tables for
lunch and/or dinner. Advance booking for 2 or 7 days/as you wish. After the request from
user, respond to him that you will confirm the request within 5 minutes. Check availability
and send SMS confirming the same. If the SMS is delivered then assume that the customer
is genuine. If the SMS is not delivered properly, discard the user request, as it is not genuine.
i) How can you take names and email Ids of the customers during the process?
ii) What can you do for repeat customers? How will you identify the repeat customers?
iii) If there is request for a team size greater than the table size, what will you do? E.g.
request for 10 persons when table sizes are 6, 4 and 2.
All the Best!
All Practice Problems for Amazon !
53
Chapter 10. Set 9
Source
https://www.geeksforgeeks.org/amazon-interview-set-8-2/
54
Chapter 11
Set 10
55
Chapter 11. Set 10
56
Chapter 11. Set 10
b. I was asked couple of questions which I already knew and I told him and we moved on
to next questions. I don’t remember what he asked.
c. If tree is BST or not. Coded it.
4. Onsite: with One Manager and Senior SE.
a. Discussion on my current Project. Quite a good discussion. It took quite a good time.
They asked me what more enhancements I can think of for features, I made in my project.
I explained few different things that I could think on the spot and they liked it.
b. Linked list with a “mad” pointer along with “next” pointer in it, mad can point any
where(can be null as well). Return clone of given such linked list.
I already knew the best approach for this. Then he asked me to think something else. I
mentioned Hash. He was okay with it and we moved on.
c. Replace the elements in an array with the next following greater number of it from right
side of the element.
I told him I already know this and I asked if he wants me to explain the algo. He said
so and I explained. Then we moved on.
d. Reverse each K nodes in linked list.
e.g. 1->2->3->4->5->6->7-_ given
output 3->2->1->6->5->4->7-_
e. Two strings S and S1. Remove all chars from S which are present in S1.
Explained them all possible methods for this what I could think of(with space, without
space). Finally, they were looking for BitMap solution. I explained that as well before one
mentioned it.
f. Design a Chess game.
Gave different classes and their relations, some procedures, then cross questioning and I
was able to give all answers which he mentioned quite reasonable.
They were okay with the design.
In the whole interview process I was asked like 8-10 questions which I already knew and I
mentioned the interviewers same. I was told why you read so much.
Overall, it was quite a good experience for me. I liked the way interviewers were interacting.
They were very supportive and friendly as well.
Unfortunately, I was not selected. � I have no idea what they were looking for.
Source
https://www.geeksforgeeks.org/amazon-interview-set-10/
57
Chapter 12
Set 11
58
Chapter 12. Set 11
Source
https://www.geeksforgeeks.org/amazon-interview-set-11/
59
Chapter 13
Set 12
2nd Round
1. https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/
2. There are some glasses with equal volume 1 litre. The glasses kept as follows
1
2 3
4 5 6
7 8 9 10
You can put water to only top glass. If you put more than 1 litre water to 1st glass, water
overflow and fill equally both 2nd and 3rd glass. Glass 5 will get water from both 2nd glass
and 3rd glass and so on..
If you have X litre of water and you put that water in top glass, so tell me how much water
contained by jth glass in ith row.
Example. If you will put 2 litre on top.
1st – 1 litre
60
Chapter 13. Set 12
Source
https://www.geeksforgeeks.org/amazon-interview-set-12/
61
Chapter 14
Set 13
62
Chapter 14. Set 13
Make an efficient data structure for storing 3 days of information of all those customers who
have visited site exactly two different days and searched more than 3 unique pages of the
site in those 2 days.
So whoever visited site exactly two days out of these three days and visited more then 3
unique pages should be in the contact list.
After final round got a regret mail after 3 days that I was Not selected.
Source
https://www.geeksforgeeks.org/amazon-interview-set-13/
63
Chapter 15
Set 14
64
Chapter 15. Set 14
Q2. Given a linked list contains even and odd numbers. separate the list into two lists
contains odd/even numbers.
Q3. Given a 2D matrix which contains 0’s and 1’s. Given two points of matrix whose value
is 1. Find the path(with only 1’s) between the given points
Round 5 (F2F with Senior Manager)
Project related questions
Challenging tasks done so far
Q1. Given a large file which contains m rows and n columns. Given a column no, sort the
column in such a way that corresponding rows also sorted
Round 6 (F2F with Developers)
Q1. Print all pairs(sets) of prime numbers (p,q) such that p*q <= n, where n is given
number
Q2. Given a binary tree, if parent is 0, then left child is 0 and right child is 1. if parent is
1, then left child is 1 and right child is 0. Root of the tree is 0. Find the kth node value
which is present at Nth level
Q3. Longest monotonically increasing sequence in O(NlogN)
I couldn’t make it. Hope it helps someone else.
Source
https://www.geeksforgeeks.org/amazon-interview-set-14-2/
65
Chapter 16
Set 15
66
Chapter 16. Set 15
eg:
Tree is:
1
2 3
4 5 6 7
would become:
1
2-->3
4--->5--->6--->7
Source
https://www.geeksforgeeks.org/amazon-interview-set-13-2/
67
Chapter 17
Set 16
68
Chapter 17. Set 16
c. What is thrashing ?
d. Real world application of heaps?
e. Minimum spanning tree and topological sort .
T4.
Around half an hour HR then
Given a function node* inplacemergesort(node* n1, node* n2) which takes 2 linked lists as
input and performs in-place merge sort and returns the final list. How will you test it and
make sure it does what it claims.
I was hired � .
The interviewers were very friendly, patient and looked for optimal solution to each question
.
I am very thankful to geeksforgeeks for such a great site and the way its maintained.It really
helped me a lot for my preparation. Keep up the good work guys �
Thanks.
Source
https://www.geeksforgeeks.org/amazon-interview-set-16/
69
Chapter 18
Set 17
70
Chapter 18. Set 17
Source
https://www.geeksforgeeks.org/amazon-interview-set-17/
71
Chapter 19
Set 18
for(i=0;i<n;i++)
72
Chapter 19. Set 18
for(j=0;j<n;j++)
cout<<a[i][j];
for(i=0;i<n;i++)
for(j=0;j<n;j++)
cout<<a[i][j];
Source
https://www.geeksforgeeks.org/amazon-interview-set-18/
73
Chapter 20
Set 19
74
Chapter 20. Set 19
b. Set of stocks for each day have been given. Need to find the days on which I buy and
sell share to earn max profit, alongwith finding the max profit.
Had to write the code, which I was able to do well.
He was impressed and I felt I had a good chance.
4th Round : Developer
a. Find top k searched elements from a continuous stream of data.
I remember we needed to use Min Heap but his constraint was using a continuous stream.
Finally was able to do it with his help.
b. Some design question based upon his team’s problems.
Had to use a queue and a hashmap to solve it.
He was very much interested in whether I could identify the complexities correctly.
5th Round : Manager – Different Team
a. Given a linked-list and 2 integers k & m. Reverse the linked-list till k elements and then
traverse till m elements and repeat.
Write production quality code.
I am not sure what happened and why I fell off on such an easy question, but you just can
do something like that in the last round.
b. An array of elements have been given. Find for each element, first max element to its
right.
Was able to do it well, however lost it on complexity analysis.
c. Boundary traversal of a tree. Write the code.
Wrote the code, however he was not able to check the same as took a lot of time.
Before this round, I had good hope of getting selected, but no one can give such a bad last
interview and get selected and hence after 2 weeks got a rejection mail.
Source
https://www.geeksforgeeks.org/amazon-interview-set-19/
75
Chapter 21
Set 20
76
Chapter 21. Set 20
Initial set up cost would be big but the same trie can be used for any email by making all
counters to zero.
Third f2f)
1) He talked almost for 45 min regarding my project and asked how we implement it. I was
also working on web services in my current company, so they were more interested in asking
questions there and want to know how well I implemented there.
2) A design question of chess int board[8][8] each value in the matrix represents a character.
1-9 number represents all whites and 11-19 represents all blacks.
Given a pawn at (x,y) print all possible moves. Assume whites are index 0 and blacks are
at index 7.
Fourth f2f)
1) There is ternary tree in two dimension space(one plane). Print all elements that are
visible from right side of the plane(If you see along y axis plane)
eg) In the following answer would be (1) (5) (8)
————————(1)—————————————
—————-(2)–(3)–(4)–(5)——————————
———-(6)–(7)–(8)—————————————–
2) Print these elements in a zig zag order, first level1 and then level n, level 2 and level n-1
and so on.
In simpler words print rightmost ending element in each level of a ternary tree.
My approach was take two queues, enqueue root in Q1 and while dequeueing enqueue its
childeren in Q2, while shuffling elements from one queue to another store the last element
in doubly linked list.
While printing, use this double linked list, remove from head and then tail, till it becomes
empty.
Fifth f2f)
1) Find jth element in ith row of a pascal triangle
1
1 1
1 21
1 331
1 4 6 4 1… and son on. pascal(4,2) should return 6.
complexity is bad and I am not grouping the solution once calculated of sub problems
2) Implement your own hash function with keys as strings and values is of type Object
initially I told BST with insertion deletion of order log(n), then he told me to think and
answer then I told self balancing BST and he asked me to implement,
77
Chapter 21. Set 20
Source
https://www.geeksforgeeks.org/amazon-interview-set-20/
78
Chapter 22
Set 21
79
Chapter 22. Set 21
80
Chapter 22. Set 21
2. Zigzag traversal of binary tree. (more optimal solution is expected from you).Complete
code should be written and they will check later.
3. A robot is there in 2D space, which can move to its left direction. You are given with an
array which are moves of robot, which starts from origin(0,0). Find the rectangle covered
by it.
I/P: { 2,3,4,5,6,1,3,5,5} starts at (0,0)
O/P: rectangle points: ( -4,4 ) to (4,-2)
4. Casual discussion about hiring process.
F2F Round 3 (with Developer 50min):
1. Data structure which does insertion, deleting latest item, find min, find max in O(1) time.
(Gave hash, 2-D, linked list, many .. He impressed lot here)
2. Vertical sum of a tree. (Column wise sum – can find same one in geeksforgeeks)
3. Find n-th digit in the continues sorted stream of data.
I/P: {1,2,3,4,5,6,7,8,9,1,0,1,1,1,2,1,3,1,4,1,5,1,6,1,7,1,8……… infinite} n =28
O/P: 28th digit
Complexity analysis of all the above.
F2F Round 4 (with Developer 45 min):
1. Print matrix spirally.
12345
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
O/P: 1 2 3 4 5 10 15 20 25 24 23 22 21 16 11 6 6 8 9 14 19 18 17 12 13 18
2. Write a function to check syntax of opening and closing braces whether they are proper
or not.
3. Same question if you have k types of braces( ‘(‘ ‘[‘ ‘{‘ ,…. K types) All are of same
priority.
4. Same question if you have k types of braces( ‘(‘ ‘[‘ ‘{‘ ,…. K types) All are of diff priority.
5. Print all valid combinations of k number of pairs of braces.
6. Return count of above combinations without using algorithm for printing them.
7. Memoziation –do you know about it. Explain me.
F2F Round5 (Bar Raiser round) 60min:
1. Leader ship principles followed by Amazon
2. About project.
3. Why you are leaving prev company, What will stop you there.
4. Set of strings are given in a dictionary order. The problem here is order is not as our
alphabetical. It may be different. C may come before a,b, x may come before d,c. etc. You
will have to find the order of characters by using given input. (topological sort – complete
code is required to write)
81
Chapter 22. Set 21
5. Binary search tree into Sorted doubly linked list (Expected Inplace algorithm)
Things to keep in mind:
1.For every problem, give one simple solution first (may have more time complexity) and
think for optimal solution.
2.Write a code in clear manner. It should be understandable without your explanation.
3.In a position to tell complexity for code you are going to write.
4.First tell the algorithm or approach and proceed with writing code.
5.Do not hesitate to ask for clarification. They will impress.
That’s all from my side. Best of luck.
Thanks again for GeeksforGeeks, a lovable website for techies.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-21/
82
Chapter 23
Set 22
83
Chapter 23. Set 22
1
2 3
4 5 6
7 8 9 10
No each bucket is resting on 2 buckets. I will add water in the top bucket(number 1), after
filling the bucket completely access of water will spill to the left and right bucket. Need to
write a function which will return water in nth bucket after I will add x L of water in bucket
number 1.
float getWaterInBucket(float x, int n);
2. Given an mxn matrix. Each entry is a room. Rooms containing “L” are locked. No one
can enter a locked room. Rooms with “G” are guarded rooms. Distance of a room from a
Guard is defined as the minimum number of rooms that are encountered for the Guard to
reach that room (Guard can move in all allowed 4 directions at max). Find the room that
is farthest from all guards. Expected time was O(mn). (Hint: BFS)
84
Chapter 23. Set 22
9. Given a binary tree with parent pointer only. Given pointers to two nodes in the tree,
find the LCS(Least Common Ancestor). Quality Code was required with proper handling
of boundary cases.
10. Object oriented design of ‘Snake and Ladder Game’. Was asked to propose classes,
inheritance and reasoning behind it.
Face to face: Round 5(Manager, 1 hour 10 minutes):
1. Tell me about yourself. It starts with a basic intro round, where your communication
skills are judged.
2. Why changing the job?
3. Explain in detail the current project. In depth information.
4. Given a binary tree. Tell if all the leaves are at the same level. Code was required with
proper handling of boundary cases.
5. Discussed how the stock market works. Reached to:
Design a data structure for storing the stock prices of various stocks. Make design such that
update (new entry addition) of prices can be done efficiently. Also, it should be efficient
to answer the queries like, “Maximum/minimum of stock prices of stocks s1, s2, s3 in the
month of November 2012 etc.”
Four days later I was informed that I was selected �
Following materials I used for preparation.
1. GeeksforGeeks
2. Careercup
3. Introduction to Algorithms(Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest,
and Clifford Stein)
4. Algorithm Design [Jon Kleinberg, Éva Tardos]
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-22/
85
Chapter 24
Set 23
86
Chapter 24. Set 23
87
Chapter 24. Set 23
that we do not have a suitable opening at present that does justice to your aspirations and
capabilities. Hence we would not be able to take it forward at this juncture.
With your permission, we will retain your details in our database and would get in touch
with you, should there be a suitable opening in future.
Wish you all the best in your endeavors.
I am still not able to find the correct reason behind it. And Now I am frustrated.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-23/
88
Chapter 25
Set 24
89
Chapter 25. Set 24
90
Chapter 25. Set 24
Source
https://www.geeksforgeeks.org/amazon-interview-set-24/
91
Chapter 26
Set 25
92
Chapter 26. Set 25
93
Chapter 26. Set 25
technology):
(After 1 week of last interview)
Q1) Lots of discussion on my current project. Different behavioral questions were asked
during the discussion.( about half n hour discussion)
Q2) Given a cube of size N. which was constructed by N^3 number of 1 unit smaller white
cubes. Now you dipped that cube in a black color paint and taken out.
after that how many cubes are still in white color. Prove your answer( by writing mathe-
matical equations)
Q3) There are N bolts each of which different size and N nuts, they are also with different
sizes. and each bolt fits with exactly 1 nut.
Give an algorithm that combines those N bolts and nuts into N pairs of Matched bolt and
nut.
HR told me on last interview day that I would be notified by the result within two working
days as already the whole process was delayed for so many days. I had waited for almost 1
week and send them mails & called them about my candidature but did not get any response.
I was almost lost hope. But, Finally after 8 days of last interview, got a call that I was
offered SDE1..( I guess, They were not completely satisfied by in design part but I did better
in algos, problem solving and coding part and as a result I was offered SDE 1). In the end
I rejected to join at Amazon as I got another competitive offer.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-25/
94
Chapter 27
Set 26
95
Chapter 27. Set 26
Source
https://www.geeksforgeeks.org/amazon-interview-set-26/
96
Chapter 28
Set 27
97
Chapter 28. Set 27
98
Chapter 28. Set 27
Source
https://www.geeksforgeeks.org/amazon-interview-set-27/
99
Chapter 29
Set 28
100
Chapter 29. Set 28
functions. I had done it before and told him the same. I used Newton-rapson method to get
the solution but he wanted it through something on the lines of binary search. I almost got
the solution but may be I was running out of time so he dropped the question there only
and asked me to dictate the solution of 2nd problem.
Two days later I got a call that I have cleared my telephonic round and have to be present
in Hyderabad for further rounds(four). Arrangements done my Amazon and I appeared for
the further rounds on 27/4/2013 in their Hyderabad office.
Onsite:
Round 1 (Technical):
1. First question was to find the vertical sum of a binary tree. I told him the solution using
and array/hash. Whenever we move left we decremented the index while moving right we
increment the index. The solution looked fine to him but he wasn’t very comfortable with
negative indexing. So he asked for another solution using doubly linked list. Initially I
wasn’t getting it but when he gave some hint I was bale to solve it but it took some time to
cover edge cases. With the final solution he looked convinced.
2. Next question was to have Stack operations of Push, Pop, and FindMax in O(1) time. I
started doing this using only one index of max variable but than I realised I needed max
index at all levels so gave him a solution using two stacks. One having the element and the
other having the corresponding max index. He looked convinced with the solution.
Round 2 (Technical):
1. In second round there were two interviewers and coincidentally one of them was the
same guy who took my telephonic interview. First question was related on how to chose
the ‘related’ items list whenever a product is displayed on Amazon website. the problem
was to find the least related product for a given product. Initially I answered using n-ary
tree but told him that we would have duplicate entries. He asked for optimized solution so
I suggested using adjancy-list nut finally realized that it can be solved using graphs. They
were convinced and asked to code. I solved it using a Queue so while traversing a matrix
we pushed in the elements in the queue with their level of relation. They were convinced
with the solution.
2. Second question was to delete an element from doubly linked list. I solved it but missed
out on and edge case where the element to be deleted is not present in the list. I added that
check later.
3. Third was that for a given BST invert the signs of the elements and finally have a new
BST. It clicked my mind that after sign inversion it will be a mirror tree and gave the
solution for the same.
Till this time feedback looked fine.
Round 3 (Technical-Managerial):
1. The next interviewer was senior guy and asked me about my work. Explained him in
detail.
2. Later he asked me that for a given binary tree having three address fields i.e. left, right
and bfs successor, left and right fields are filled and the successor field is to be filled. I solved
it using level order traversal with a queue but he wanted solution without using extra space.
I was taking time to solve it when he gave hint about keeping track of the parent. After
this hint I was able to solve it with few conditions missing but with his intervention I was
able to give a working code (as looked to him and me).
101
Chapter 29. Set 28
Round 4 (Technical-Managerial):
1. There were two interviewers. First question was tell me about yourself and your work.
2. Given a m*n matrix, we need to find the number of ways by which a bot can reach the
(m-1,n-1) block if bot can move only right and down while starting from (0,0). I gave him
a solution using DP. Build the recursion tree showing the final solution. He didn’t ask to
code but asked to finds the recurrence relation. I got stuck I don’t know why. I guess this
was the start of decline. he gave some hints and I was finally able to write it, still.
3. For a given binary tree and a key, prune the tree with all the paths (root to leaf) that
have sum less than or equal to k. I was able to solve it with some hint. The solution looked
convincing.
Four days later I got a mail stating that “Unfortunately, we are unable to take your can-
didature further, at the moment. However, your credentials are extremely impressive and
we wish to retain your details on our active database. We shall get back to you as soon as
another similar opportunity opens up.”
Source
https://www.geeksforgeeks.org/amazon-interview-3/
102
Chapter 30
Set 29
103
Chapter 30. Set 29
2) Finding the element in O(m+n), in a sorted matrix which is sorted in row as well as in
column.
(I said i know this, so i just told the approach and we skip that !!)
3) Project questions, infact in all rounds it was there!!
4) Rope Puzzle :: 2 ropes are there and u need to find the 45 mins(Very generic Google
Puzzle)
4th Round >> FACE TO FACE (It was Amazing, it went thru 1hr 30 mins)
1) Find a median in running stream of numbers.
2) Find a k best or max values in the running stream of numbers.
3) Project Questions !! i Love that !!
4) State machine questions !! Gaming Questions (Bcoz m a game developer)
Questions on garbage Collection, Virtual machine (Bcoz i did project on it)
Anyway i love all those part.
5) One very nice question, i need to calculate the area for rain drop which will be holded
for bar graph(Its basically a very real world problem, i love to do that, even i did mistakes
but they guys are really awesome they helped me out to get rid of my problems)
5th Round >> FACE TO FACE (It was Damm Amazing, it went thru 1hr 15 mins)
1) I need to write recursion function for a robot which has to move from one location to
other location in a grid.
In recursion i took time to write the base cases, but finally with some hints i was able to
make it.
2) I need to code for k-heavy path approach and also need to write its recursion.
There also i was continue taking to the interviewer and clearing my doubts and using the
hints given by him. Finally i was able to code it and do the recursion also.
Every time i need to write the recursion in mathematical form and calculate the Complexity
also like we have to do normally for detecting the complexity.
I love the mathematical part and coding, its in my blood !!
3) Project Question !! Scalable problems !! Dealing with N dimension study and mathemat-
ical problems, even covering my whole resume.
Finally he was very happy and said to me that you need to think proper then code or design,
rest is awesome !!
6th Round >> FACE TO FACE (It was with the Hiring Manager,i guess, it went thru
45mins)
1) He asked me about my whole projects and lots of about my resume and my challenges
faced till now, it was good to explain all those.
2) He asked me to design an approach which will search all the valid combinations of a given
string.
104
Chapter 30. Set 29
I have given some approaches like implementing TRIE, and explained the pros and cons for
it and also the complexity of it.
Then i modified it and explained the Other approach which is better than the above by
using HASH MAP and INDEXING with buckets if valid words.
We had lots of discussion on it. and Finally he said we are looking for guys like you.
Finally i have the offer Letter From Amazon and He asked me for Coffee Or Cold Drink. I
Have taken Coffee.
NICE EXPERIENCE !! I LOVED ALL THE INTERVIEWS AND ENJOYED A LOT !!
Finally a Gold Medalist 2yr Exp. guy who is doing a very nominal job, got a Right place
to work which is AMAZON !!
Heartly Thanks To GeeksForGeeks Community And Their Coding Stuff Which is available
in Site !!
Source
https://www.geeksforgeeks.org/amazon-interview-set-29/
105
Chapter 31
Set 30
Class Node {
Char data;
Node next;
}
2. Given a Binary Search tree along with the parent pointer, find the next largest node for
the given node. Give the time and space complexity. The node Structure is
class Node {
Int data;
Node left;
Node right;
Node parent;
}
3. Given a sorted array which is rotated n number of times. Find out how many times the
array is rotated. Time complexity should be less than O(n).
106
Chapter 31. Set 30
107
Chapter 31. Set 30
Source
https://www.geeksforgeeks.org/amazon-interview-set-30/
108
Chapter 32
Set 31
iteration2: 0 -7 8 sum= 1
Hiring Manager:
1. Find the nearest leaf node from given node in binary tree..
use post order traversal.. like LCA in binary tree
2. Find the first k largest numbers from large file size. Explain solution for
1. When we have space to store K elements in RAM
2. When we didn’t have space to store K elements in RAM
Tech:
1. Design N-ary tree, to make sure that lock and unlock operations can be done with
minimum complexity (height of tree)
109
Chapter 32. Set 31
a node can be locked when its ancestors or successor are not locked.
we can a unlock a node a any time.
2. a[] = {a,b,c,d,e} b[]={f,g,h} result should be = af+bg+ch+df+eg
Tech:
1. Find maximum product of subarray in given array of integers
2. Design T9 dictionary
Bar Riser:
1. Design a tree, in which a root can have unlimited children and write a code to print each
level in separate level
2. Print the anagrams present in a huge file (each line in file contains one word and you
didn’t have any constraints like limited memory etc..) for a give string
use trie or hashmap
Like all Amazon interviews in GFG, here interviewer more concerned about edge cases and
perf perf perf perfect code.
Thanks a lot GEEKS FOR GEEKS and my dear friends Ramesh, Purush, Jhadey for helping
me in preparation.
Source
https://www.geeksforgeeks.org/amazon-interview-set-31/
110
Chapter 33
Set 32
111
Chapter 33. Set 32
112
Chapter 33. Set 32
This round went ok for me.2nd question i wrote proper code with all edge cases, but in first
I got stuck a bit.
F2F ROUND 3:
Qs-1) In a binary tree, a complete path is defined as a path from root to a leaf. The sum
of all nodes on that path is defined as the sum of that path. Given a number K, we have to
remove (prune the tree) nodes from the tree which lie on a path having sum less than K.
Note: A node can be part of multiple paths. So we have to delete it only in case when all
paths from it have sum less than K.
I was able to solve the problem and write correct working code for this.
(Hint : Think of a bottom up approach.)
Note: Values in tree can be -ve also.
Qs-2) A robot problem: No. of ways to reach from 0,0 to m,n in a m*n grid. I had to tell
recursive function only. No code required.
This round went very good for me. The first question was a bit tricky but solving it raised
my confidence.
F2F Round 4 with Hiring Manager:
Qs-1) This was mostly a HR Based round. A lot of questions about my previous work, my
initiatives, challenges I faced and many other questions.
A simple question on matrix was also there. Fill rows and cols with ones if a 1 is present in
that row or a col. Code also required.
Question based on shipment and orders etc. Eg: What all things to take care in b/w of
order placed and item shipped. What all factors and things you will consider.
I was being interviewed for transportation team. So questions based on it.
Overall, the round went well
I returned to Bangalore that night.
Few days later, I got a call from HR saying I am very close and I need to appear for another
round in Bangalore office.
F2f Round 5:
About half an hour Hr based discussion.
Then two Technical questions with code:
Qs-1) In a binary tree, return true if all leaves are at same level and return false if all leaves
are not at the same level.
Qs-2) An array is given which is first increasing and then decreasing. Find the pivot element.
Need to take care of all the edge cases.
This round went well for me. Mostly this round was on soft skills. I did well in coding
questions and wrote proper code for both.
In the evening I got a call from HR that I was selected. �
I would like to thank GeeksForGeeks Team for being a great help for me.
113
Chapter 33. Set 32
Source
https://www.geeksforgeeks.org/amazon-interview-set-32/
114
Chapter 34
Set 33
1
2 3
4 5 7
115
Chapter 34. Set 33
116
Chapter 34. Set 33
1 5 13 29
11 16 25 38
45 49 52 57
51 54 59 66
Source
https://www.geeksforgeeks.org/amazon-interview-set-33-2/
117
Chapter 35
Set 34
118
Chapter 35. Set 34
119
Chapter 35. Set 34
me it will be a question you have not heard of before. At the end of round, he showed me it
was a question from top coder, but I had never heard of anything called top coder before.
Question 1: Given a string, find the longest sinusoidal sequence in it. If there are multiple
such sequences of same maximum length, return the one which comes first in lexicographic
order in a dictionary..
Sinusoidal means increasing then decreasing then increasing and so on.
Example ::
a r u n ::
a u n , a r n , r u n are three such sequences of length 3…. But, a r n is output since it
comes first in lexicographic order.
Interviewer gave me hints that if I had to found the sequence in which all elements were
increasing, then I answered LIS will give me the solution , this was the hint. So, basically,
it was a variation of LIS. I answered it in O(n2) and 2n space….
Then was asked to do it in (n) space and o(n).
Question 2: Suppose a student needs to implement a bst structure to solve a problem,
but instead he used a linked list…. Then give an example of input sequence, in which his
implementation works… new value will always be added at beginning of a linked list.. so.
Basically at each step after insertion , root of bst and head of link list should point to same
node. I was asked to provide the sequence.
Source
https://www.geeksforgeeks.org/amazon-interview-set-34/
120
Chapter 36
Set 35
121
Chapter 36. Set 35
eg 1-2-3-4-5-6-7-8
o/p--
1
/ \
3 2
/ \ / \
4 5 6 7
\
8
Source
https://www.geeksforgeeks.org/amazon-interview-set-35/
122
Chapter 37
Set 36
123
Chapter 37. Set 36
Q-1)
n1 pairs of “{} ” brackets
n2 pairs of “[] ” brackets
n3 pairs of “() ” brackets
I have to find the all valid combinations of all the pairs. I have to write the working code
of it.
I gave him the solution with recursion and stack.
3rd face to face round
————————————-
Interviewer asked some basics Questions on Design patterns, OOPS and OS,after the big
Discussions of all the Questions he asked 1 coding questions.
1st Question
————
There is a string, in which all the spaces are removed, we have to find the original string
with the help of a machine which takes input a word checks that it is valid or not.
Telephonic Interview
————————————-
The Interviewer asked to give a brief idea about my project.
After some questions on my Project, the interviewer asked 2 coding question
Q-1) tree to doubly link list. O(n) and in-place solution is required.
Q-2) A array of N elements, we have to replace all the elements with nearest greater which
is present on the right side of that elements. O(n) is required.
After 2 days, they inform me that I am selected for the job. �
Source
https://www.geeksforgeeks.org/amazon-interview-set-36/
124
Chapter 38
Set 37
(1)
/ \
125
Chapter 38. Set 37
(2) (3)
\ /
(4,5)
node 4 and 5 are overlapping
Tree 2
(1) (4)
/ \ \
(2) (3) => Rotated one (2) (3)
/ \ /
(4) (1)
126
Chapter 38. Set 37
4th round was type of HR as he wants to know about myself and how I do different things.
If I stuck in a position what will I do.
If your boss says that you have to do X and you are not satisfied with this then what will
you do and how will you approach.
After that I waited for 3 hours and I got selected with 4 of my friends �
Hope this will help, I try the possible way to support you.
All the best for your placements �
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-37/
127
Chapter 39
Set 38 (SDE-I)
128
Chapter 39. Set 38 (SDE-I)
case (i): Tree is complete and no node’s x-coordinate is overlapping. (i.e all nodes will
expand along x-axis so that no node overlaps). (Code)
o(0,0)
/ \
o(-1,-1) o(1,-1)
/ \ / \
o(-2,-2) o(-1,-2) o(0,-2) o(1,-2)
Here we can see that many nodes are overlapping over x-cordinate.
case (ii): Tree is incomplete and no node’s x-coordinate is overlapping. (Approach)
case (iii): Tree is incomplete and node’s x-coordinate can overlap. (Approach)
b. Design a DS to perform
Insert
Search
Delete
get Random
All in O(1).
Soln: Focus on Delete and get_Random. On further analysis, only get_Random was re-
quired to me modified. Only a bit of tweak will serve the purpose.
5) In-house 3
a. Given array of ints. Assuming total no. of elements is even. Need to tell whether this
array can be grouped in sets of pairs such that sum of each pair is divisible by K.
eg: 0,2,4,8,12,20,18,4 and k=4
so (0,8), (2,18), (4,20), (4,12) is one such set in which sum of each pair is divisible by k.
(Code)
b. There is a vertical rod. Discs of various radiuses are inserted in it. When we will try to
take out any disc then 1st all the discs above it has to be taken out. Taking out a disc and
putting it back is counted as one step.
Considering this, what will be the minimum no of steps in which these discs of various radius
can be stored in sorted order in the rod.
Only minimum no of steps was required. “How to sort” was not required. (Approach)
c. Given array of ints. find ar[i],ar[j] such that j>i and ar[j]-ar[i] is maximum. Famous
problem. (Code)
6) (Semi Technical- Hiring Manager)
a. Normal HR questions. Why Amazon over your previous company, some areas where you
want to improve, define dream job and similar other questions as per the discussions.
As per feedback: my answer for “Why Amazon over prev company” was not clear here.
b. Given two arrays of ints of size m and m+n in sorted order. merge it inplace. Famous
problem. (Code)
c. Given string.
Qusn: Find the char occuring max no of times.
Soln: Simple one. Take auxillary array of size 256 and maintain frequency of each char.
Scan auxillary array and get the required char. O(k+n) where k=256 here.
129
Chapter 39. Set 38 (SDE-I)
130
Chapter 39. Set 38 (SDE-I)
Source
https://www.geeksforgeeks.org/amazon-interview-set-38/
131
Chapter 40
Set 39 (SDE)
132
Chapter 40. Set 39 (SDE)
eg. 1 3 2 4 5 6 7 9 8
1
2 3
4 5 6 7
8 9
133
Chapter 40. Set 39 (SDE)
Source
https://www.geeksforgeeks.org/amazon-interview-set-39/
134
Chapter 41
if(n<0)
return 0;
else
return ( n%10 + f(n/10, 2) )
6) Complexity?
7) Frog steps either 1, 2 or 3 steps to go to top. In how many ways it reaches the top?
Based on recursion, options
135
Chapter 41. Set 40 (On-Campus Round 1)
a) f(i) = f(i+1)+f(i+2)+f(i+3)+1
b) f(i) = f(i-1)+f(i-2)+f(i-3)+1
c) f(i) = f(i+1)+f(i+2)+f(i+3)
d) f(i) = f(i-1)+f(i-2)+f(i-3)
8) Based on java 2 questions, one from Exceptions
9) Preorder is given, we had to find out the postorder
10) Memory management, pa=32bit, la=36bit , frame size=2^12, first page entry, second
page entry
11) This question is from GATE CS previous question papers
Programs:
1) Print left view of binary tree
2) Sum of 3 linked list
Digit.. 123------1->2->3------------linkedlist1
234----2->3->4--------------linkedlist2
34567----3->4->5->6->7---linkedlist3
Output: 34924-------3->4->9->2->4
Source
https://www.geeksforgeeks.org/amazon-interview-set-40-campus-round-1/
136
Chapter 42
Set 41 (On–campus)
137
Chapter 42. Set 41 (On–campus)
3) Given an array of integers, find an index such that if you split the array into two parts
the absolute value of the difference between the sum of elements in both parts had to be
minimum. After giving him the logic, he changed it to split it into 3 parts such that sum of
elements in all of them are equal. I had to code this one.
Round 3 –
1) There is a sentence that your friend knows, but while giving it to you, he lost all the
spaces. You have to dictionary with you. How would you reconstruct the original sentence
using it.
2) How to delete a particular node from a circular Linked list.
3) You are given an encrypted file. You don’t know the key used to encrypt it. Like A might
be mapped to B, B to some D and D to some other F. But you don’t know this encryption
scheme. You have the dictionary with you. How will you decrypt the file? I suggested lots of
solution like exhaustive searching, then using some variants to minimize the complexity. He
gave me just a one word hint- histogram. So I gave him a logic that counting the frequency
of every letter used in the dictionary. Then replace the most used letter in the file with
the most used in the dictionary. And then compare words with the dictionary. In case of a
mismatch back –track and use the second largest and so on. I also discussed with him that
it could also have high complexity in worst case, but he moved on.
4) What is indexing in DBMS. How will you implement an index.
Round 4 –
1) A complete path in a tree is from a root to a leaf. A k-heavy path is a complete path
whose sum of elements is greater than k. Write a code to delete all nodes which are not in
any of the k-heavy paths.
2) You have an array whose elements firstly strictly increase and then strictly decrease. You
have to find the point of change.
All the questions in all the rounds required the minimum possible complexity possible (both
time and space). And I had to write the code of my final solution as well. Finally the results
came and I was selected by them.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-41-campus/
138
Chapter 43
Set 42 (On-Campus)
139
Chapter 43. Set 42 (On-Campus)
and resulting color is (color1+color2)% 100. Keep on mixing colors such that you end up
with just one jar with minimum smoke.
12. A question on paging, processes also.
Selected … thanks to geeksforgeeks team.
Source
https://www.geeksforgeeks.org/amazon-interview-set-42-on-campus/
140
Chapter 44
Set 43 (On-Campus)
141
Chapter 44. Set 43 (On-Campus)
3. Maze solve problem. Given a matrix with 1s and 0s, 0 represents free path, 1 represents
blocked area, and you can move in any of the 8 directions. Find the path from source to
destination and print it. Then he told me that he can change destination at run time. And
asked me to do for that.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-43-campus/
142
Chapter 45
Source
https://www.geeksforgeeks.org/amazon-interview-set-44-for-internship/
143
Chapter 46
144
Chapter 46. Set 45 (For Internship)
Source
https://www.geeksforgeeks.org/amazon-interview-set-45-internship/
145
Chapter 47
Source
https://www.geeksforgeeks.org/amazon-interview-set-46-campus-internship/
146
Chapter 48
147
Chapter 48. Set 47 (Off-campus for SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-set-47-off-campus-for-sde-1/
148
Chapter 49
149
Chapter 49. Set 48 (On-campus for SDE-1)
I used sorting to solve this problem, so some follow up questions about which sorting tech-
nique i would prefer here.
What is the difference between merge sort and quick sort and when quick sort is preferred
over merge sort, etc.
2. Two strings are given. One of them is the initial string and other string contains characters
as per their priority. Sort the initial string as per the given second string. characters in
initial string may or may not be present in the second string. If not present, sort them in
lexicographical order at the end of output.
eg. String1 – ddloyc, String2 – odl
Output – oddlcy
Again, some discussion over various approaches to solve this problem.
Round 3 : (Face to Face)
Discussions over my projects.
1. (Reservoir sampling problem) https://www.geeksforgeeks.org/reservoir-sampling/
2. Generate all valid permutations of n pair of parenthesis. https://www.geeksforgeeks.org/
print-all-combinations-of-balanced-parentheses/
3. Given a bst, update the value of every node with sum of value of all nodes greater than
and equal to the value of current node.
Counter Question : I had used global variable for this purpose, so he asked me to solve it
without any global or static variable.
4. Inorder Successor of a node in bst.
5. Given a list and a number k, invert first k elements and leave next k elements. Repeat
this throughout the list.
Round 4 : (Face to Face)
1. N number of jars are kept in a linear fashion. Each jar contains a color whose value
ranges from 0-99. Now you can mix any two adjacent jars having colors ‘a’ and ‘b’ (both
integers), and it will produce a new color of the value (a+b) mod 100 and will also produce
smoke with value (a*b). Mix all the jars in a way such that in the end only one jar remains
and total smoke produced is minimum.
Day 2 :
Round 4 : (Telephonic with someone very senior)
He said that i must have been through many coding questions already, so he will start with
the basics.
1. What is the difference between C and C++ ?
2. Which one will you prefer, when and why?
3. What is the difference between C++ and JAVA.
4. Which is better, C++ or JAVA. Support your answer.
5. Give one use case where C/C++ can use pointers to solve it, but it can’t be done in
Java.
6. Again, some discussion over my projects. Which project i liked most and why? What
problems did i face during that
project and how i handled them.
7. Given a stream of 0’s and 1’s in which 0’s come first and then 1’s, find the first occurrence
of 1.
8. Design a data structure for phone-book of mobile phones. Implement it and discuss
about its benefits and limitations.
150
Chapter 49. Set 48 (On-campus for SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-set-48-campus-sde-1/
151
Chapter 50
152
Chapter 50. Set 49 (On-campus for SDE-1)
b) if you lose a round, the bet amount will be reduced from your total sum and next bet
will be twice the previous.
c) game ends when all the rounds are complete or you dont have sufficient sum.
Initially, you are given with a string of the form “WLWWL” where W indicates a win and
L indicates a loss and initial sum. Initial bet amount will be $1.
Function prototypes and main was given for both questions.
Round 2 : (Face to Face)
The interview started off with a light discussion about myself, achievements. Then he asked
me about my project and the difficulties faced. Then we moved on to coding problems.
Q1: You are given an array in which you’ve to find a contiguous subarray such that the sum
of elements in it is equal to zero. (I coded using hashtable in java)
Q2: Given a binary tree. Find out if it is a binary search tree or not.
Round 3: (Face to Face)
Q1: You are given a generic tree. Design a structure for it. Now for every node of the tree
make the leftmost child of the node as a duplicate of the node itself and return the root of
the tree.
Q2: He: Tell me the time complexity of 8-queen problem.
Me: (I did not exactly remember the complexity so I coded)
Round 4: (Face to Face)
He asked me variety of theory questions, I was stumped as I did not know many things. He
asked me about ACID properties, oops concepts, SQL etc. out of which I could answer only
a few.
Then we switched over to coding.
Q1: He: You are given various time intervals and you have to merge the overlapping ones.
Me: I had already coded it in the Code Ninja questions on the amazon’s website, so he just
asked me the approach to the question.
Q2: You are given a binary tree. Tell me if it is height balanced or not.
Round 5: (Telephonic)
The interview started with if I had any questions, and then proceeded with the projects I’ve
done.
Q1: You are given a file with many words. You are given a word as an input and you have
to find every anagram of that word in the file.
Q2: Given two words, tell if they are anagrams or not. Extend your solution for unicode as
well.
Finally after a long wait of almost 8 hours the result came and I was hired!! � �
I would like to thank geeksforgeeks for all the pain they take in compiling every article so
that people may understand every concept clearly.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-49-campus-sde-1/
153
Chapter 51
154
Chapter 51. Set 50 (On-campus for SDE)
1 7
4 3 8 2
1
Source
https://www.geeksforgeeks.org/amazon-interview-set-50-campus-sde/
155
Chapter 52
156
Chapter 52. Set 51 (On-campus for SDET)
2. In the same (M X N) matrix I have to print the matrix in increasing order of elements
.write code for it(I used heap for that purpose and used concept of merging k sorted array).
3. Given an array , each element is one more or one less than its preceding element .find an
element in it.(better than O(n) approach)
4. Given two strings STR1 and STR2 .we need to find longest substring in STR1 whose all
characters are taken from string STR2(was asked to write code for it in optimal time)
STR1-abcdefacbccbagfacbacer
STR2-abc
ans : length : 7
acbccba (from position 7 to 13)
5. Given a binary tree. I need to print the nodes in vertical line zigzag manner. For example:
1st vertical line from top to bottom, 2nd vertical line from bottom to top,3rd vertical line
from top to bottom and so on
5
/ \
3 7
/ \ / \
1 4 6 8
/ \ \
2 9 10
Answer would be –
1
23
546
97
8
10
Round 3: (face to face ) (50-60 minutes)
I was asked about my project in details. He asked me project related questions for first 20
minutes.
Next he asked to convert a binary tree in a doubly link list.
I told him various approaches like by using space complexity and in-place conversion.
I was asked to code all those approaches.
Then he gave a hint about one more approach and asked to code it.
Round 4: (face to face) (60-70 minutes)
Again, I was asked about my project in details and he was questioning me on every part of
it. Next he asked me to name the subjects that I have studied so far � . He asked many
theoretical questions on database management systems, SQL, operating systems, OOPs
concepts and their real life examples and also two coding questions.
157
Chapter 52. Set 51 (On-campus for SDET)
Source
https://www.geeksforgeeks.org/amazon-interview-set-51-campus-sdet/
158
Chapter 53
159
Chapter 53. Set 52 (For Internship)
Source
https://www.geeksforgeeks.org/amazon-interview-set-52-internship/
160
Chapter 54
161
Chapter 54. Set 53 (For SDE-1)
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 which would return all the letters for the number. solved it using recursion.
its quite similar to permutation of string. .
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
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.
162
Chapter 54. Set 53 (For SDE-1)
1
/ \
2 6
/ \ / \
3 7 8
/ /
4 12
/ \ \
5 9 13
\ \
10 14
\
11
163
Chapter 54. Set 53 (For SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-set-53-sde-1/
164
Chapter 55
Input:
165
Chapter 55. Set 54 (For Internship)
I reversed the linked lists and simply added the corresponding nodes along with the carry.
Then he asked me to solve the question without reversing the list. Then I solved the question
iteratively without reversing the lists.
The interviewer then asked me to write a recursive code for the same problem.
After that he asked me to modify the code so that the carry at each place is passed by value
instead of using pointers(which I had used in my code).
Question 2: iterative and recursive code to reverse a linked list(Take Care of corner cases:
when list has no nodes or contains a single node)
Question 3: Write a function to check whether a binary tree is a sub-tree of another binary
tree (Check for all corner cases).
I solved it in O(n^2) time complexity. He did not ask me to optimize my code.
Question 4: Which data structure would you use to keep records of stock market?
I asked him to clarify the problem statement.
He then asked me : Suppose you have to maintain the stock values of various companies
during various periods and return minimum stock value of a particular company over a given
period of time.
I answered segment tree (Probably the correct answer was queue data structure).
However the interviewer proceeded with questions on segment tree.
He asked me to write a code for
a) Creating a segment tree
b) Performing range minimum query in a segment tree
c) Updating the segment tree
He asked me to analyze the time complexity for building the segment tree and performing
the range minimum query in the segment tree.
He then asked me: If you are to maintain the stock value of a company for the past 6
months..then you have to update the segment tree every day by deleting a stock value and
inserting a new stock value. How would you do that?
Here I got stuck and could not perform the updation in better than O(n) time.(However
using queue it can be performed in O(1) time) .
He finally asked me if I had any questions.
Round 3: (face to face) (20 min)
Only one technical question was asked to me in this round.
a) He asked me to speak something about myself and my technical achievements..
b) How to store a binary tree in a file & then read back.(It is not necessarily a BST)
First I answered that I would store level-order traversal of the tree.
He then asked me how I would maintain the nodes at various levels (which I was unable to
answer). So, I changed my approach and told that: I would store in-order and pre-order
traversals of the tree from which the original tree can be easily retrieved.
166
Chapter 55. Set 54 (For Internship)
But then he told me to optimize my approach (As this approach would require twice the
original space to store the data in the nodes). I could not further optimize my approach
(However the better approach was to use parenthesization.
A
/ \
B C
/ \
D E
If this is the binary tree then it can be stored as (A(B(D),(E)),(C)) in the file.)
c) Then there was a 10 min discussion my project , the problems I encountered and how I
solved them.
d) Finally he asked me if I had any questions.
I asked about the intern projects at Amazon and the use of DBMS and NETWORKING in
it.
He started elaborating the entire work-process at Amazon and his work-experience……..most
of which I could hardly understand. He also told me to have a good knowledge of JAVA as
it will be required at some stage during the projects.
Finally I got selected.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-54-internship/
167
Chapter 56
168
Chapter 56. Set 54 (Off-Campus For SDE-1)
F2F Interview 1:
1. Find the longest even length palindromic substring in a string.
2. The interviewer asked me what are the data structures I know. I told him many of them.
He chose HashMap and asked many detailed questions about it.
F2F Interview 2:
-Tell me about yourself and the work you are doing currently.
1. Write power function. Eg. 2^3=8. Optimize it as much as you can. Simple.
2. Longest path in a Binary tree.
F2F Interview 3:
-Tell me about yourself, your work, strengths and weakness, challenges you have faced in
current job, why Amazon.
1. I don’t remember it exactly, but it was probably : Delete a node with value K from
unordered Circular Link List. Algo is straight forward. Production level working code was
required.
2. Make OO design for 2-players game of chess.
3. You have some packages and you have to decide the build order for them.
A package should be built before the packages that depend on it.
For example. A={B,C}, B={D}, C={}, D={E}, E={}, F={}
So one possible build order for package “A” is E, D, B, C, A.
You have to write a function which will take the package name and will return its build
order. You have API which will return you the list of packages on which calling package
depends on. For example, the API will return B and C in a list when you call it providing
the parameter as package A.
F2F Interview 4:
-Tell me about your work and challenges you have faced.
1. You are given a binary tree in which every node has left, right and a next pointer. Next
pointer is null initially.
You have to modify the tree in such a way that every node’s next pointer will point to the
next node on the same level.
O(1) space complexity code was required to be written.
Eg.
1 1
2 3 ======> 2----------------->3
4 5 6 4-->5----------------->6
ANSWERS:
Telephonic Interview:
1. It can be a recursive procedure.
For example, for 7 3 1 4 5 6. I can write a procedure like “public int getEqualSumIndex(int
index, int left_sum)”
I can call it recursively like this: int right_sum=getEqualSumIndex(index++,
left_sum+arr[index])
Can have return sum like this: right_sum+arr[index];
I can compare the sum like this: left_sum==right_sum
169
Chapter 56. Set 54 (Off-Campus For SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-set-54-off-campus-for-sde-1/
170
Chapter 57
171
Chapter 57. Set 54 (On Campus for SDE)
Source
https://www.geeksforgeeks.org/amazon-interview-set-54-on-campus-for-sde/
172
Chapter 58
Set 55 (On-Campus)
173
Chapter 58. Set 55 (On-Campus)
number being selected? What is the probability of any number being selected if stream has
less than k numbers(its 1).
He asked me if I had some question. I said I had one, but I already asked it to previos
interviewer. He asked me if I got a satisfactory answer to it. I said the answer was very
much satisfactory.
Round 3 (CS Round):
He asked me if I am comfortable with writing SQL queries. I prefered not to.
1. What is an interface? Why it is used? Give an example. What is an abstract class? Why
it is used? Give example. Why 2 different concepts of interface and abstract class?
2. Do you know about singleton class? What is it? Implement a simple singleton class. I
made some mistakes in making attributes static etc. He guided me and finally I corrected
all bugs.
3. Given a binary tree, where each node has an extra next pointer. Fill the next pointers so
that each node’s next pointer points to its next sibling node. First I gave a solution where I
would require a map, where each map key will be a level number, and value will be pointer
to the last currently accessed node of that level. Then he asked me to do it without space.
Finally I gave him a solution without space. I gave a non-recursive approach, and he asked
me to code it.
Round 4(Senior SDE 3 from Seattle Office):
He told me about himself, his team, his work and his team’s work.
1. Tell me about one of your challenging project/internship/class assignment.
2. Give a situation from your life where you were given a negative feedback, and how did
you tackle the situation.
3. Explained me a cache situation, where, keys will be in cache, and each key will point to
a string. It was LRU cache condition, and I had to implement the LRU cache. Then write
a function to retrieve a string, given its key, from this cache. Retrievel should be O(1) (if
you give O(n) retrival, he will ask you to make it O(1) ).
Finally got an offer !! � �
While you are answering a question, clarify any doubts that come to you mind. Dont take
any assumptions by yourself at all.
Keep on speaking your approach as you think. Keep speaking, if possible, even when you
write code. They want to test if you really know the approach, and not just copying code.
All rounds were technical and elimination. The last round has the highest weightage in their
procedure. Write clean code, ask for some time if you want.
Thanks a lot to the GeeksForGeeks team for helping with interview preparations! �
All Practice Problems for Amazon !
Save Knights
Source
https://www.geeksforgeeks.org/amazon-interview-set-55-on-campus/
174
Chapter 59
Set 56 (Off-Campus)
175
Chapter 59. Set 56 (Off-Campus)
K from that Node .Nodes DON’T have parent pointers.( Algo + Code )
-> Implement 2 stacks in an array .( Algo + Code ) .
Follow up question ->What do we do if we want to change the size of array dynamically.
-> Implement 3 stacks in an array .( Algo )
-> Implement K stacks in an array .( Algo )
F2F Interview 4 ( 60 mins )
-> Lot of OS questions . Mutex,semaphore,Deadlock ,Virtual memory , Scheduling algos .
Then he gave me a Code, and asked to make it Thread Safe .
I had used SQL in my intership project, so was asked basic DBMS questions and SQL
queries.
SQL query to find maximum in a column, without using aggregate MAX function .
-> Given a binary tree, where every node value is a Digit from 1-9 .Find the sum of all the
numbers which are formed from root to leaf paths . (Algo + Code )
6
/ \
3 5
/ \ \
2 5 4
\ /
7 4
There are 4 leafs, hence 4 root to leaf paths:
Path Number
6->3->2 632
6->3->5->7 6357
6->3->5->4 6354
6->5>4 654
Answer = 632 + 6375 + 6354 + 654 = 13997
Source
https://www.geeksforgeeks.org/amazon-interview-set-56-campus/
176
Chapter 60
177
Chapter 60. Set 57 (Off-Campus for SDE-1)
is the main area.we need to think a data structure which will minimize the space and time
complexity of word Finding appropriate List and Inserting word).
I could do the insertion in O(1) time by keeping track of tail pointer in each list. But finding
the appropriate list needs o(n) in case of linked list, o(log(n)) in case of binary search
tree. Using hash table, you can do this in o(1), but writing a hash function is difficult
and inefficient in terms of time. Then I suggested Trie data structure.with this, we can
reduce the time complexity well. But space complexity will be more. I told all the ideas
to interviewer. They were much satisfied with this. And moved to next question(without
writing code J)
Q2: Find min and max element of an unsorted integer array.
Very simple question you can do two pass on the array and find it, but number of comparisons
will be o(2n). He asked me to reduce it.
I gave an algorithm which will do the same in O((n/2)*3) which is fairly less than o(2n).
They were impressed on my solution and asked weather I have any question .
F2F round 3: (CS fundamentals and system programming)
Questions were in C++ patterns, Network Programming, Linux, since I did project on
networking, Linux I could perform well in this round.
F2F round 4: (Hiring manager round):
Interviewer was keen on testing cultural fit. Nearly 10 to 15 questions on my previous
project,
Why amazon?
Why you want to leave previous company?
What initiative you took in prevous company?
How will you manage conflict with your manager?
How will you demonstrate ur product to customer?
F2F round 5: (bar raiser)
This also had cultural fit questions and then a data structure question.
Qn: Find the distance between two nodes in a binary tree, no parent pointers are given. I
could solve this in post order traversal in o(n) time complexity. He asked me to code in
home and send it via mail.
Geeks for geeks is my Wikipedia for interview preparations. Thanks to geeks for geeks.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-57/
178
Chapter 61
179
Chapter 61. Set 58 (On-campus for Software Development Engineer)
file corresponding to given column keeping all rows unchanged. You cannot make new text
file. Write neat code on paper.
Solution:
Round 1:
1. Make min heap of first 100 elements. For each remaining elements, if it is greater than
root (min) node then remove root node, add that element then heapify. Time = 1 billion *
log(100)
2. Simple. For i = 0 to N-1, A[A[i]%N] += N. Return i with max A[i]. O(n) time.
Round 2:
1. Find pivot point. O(log n) Binary search in both left and right arrays. O(log n)
2. Compare median of both arrays. Accordingly select right half or left half array. Repeat.
O(log n)
Round 3:
1. Make a hash table and a linked list. When you add an element add it in both hash
table and linked list. But in hash table along value caralso store pointer to the same value
in linked list. To delete an element find it in hash table, use stored pointer to delete the
same element from linked list also. For fetch any operation return head node of linked list.
Memory = 2*N
2. Preprocess in O(n) time: Make two vectors for A and B. Traverse in-order. When you
get A add its pointer in vector of A. Same for B.
Round 4:
Read whole column. Heap sort (saves memory). Now you know old indices and new indices.
Shift entire rows from old index to new index. Keep one row in temp storage to avoid
overwriting.
Some tips that may help you:
1. Always be confident for whatever you are saying.
2. Listen carefully. Ask doubts until the question is perfectly clear to you.
3. Think out loud. Start with obvious approach and then improve upon it.
4. They will test your way of approach, thinking process. Don’t give up. Interviewer may
give you hint if you are stuck.
5. Direct them to ask you about your strong topics.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-58-campus-software-development-engineer/
180
Chapter 62
181
Chapter 62. Set 59 (Off-campus for SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-set-59-campus-sde-1/
182
Chapter 63
183
Chapter 63. Set 60 (For Internship)
Now the interviewer wanted to test my understanding of operating systems and asked two
fairly direct questions, to which I gave my answer based on my understanding (not bookish
definition as I did not remember any of those � ).
Question 3 & 4:
What is semaphore and what do you mean by a deadlock.
After two days I got a call from the HR informing me I have been selected for the next
round. Now it was the time for the last and the decisive round.
Second Telephonic Round
For this round I had slightly more time than the last, due to the fact that the weekend fell in
between.The interviewer was very very cool and helping this time, something which I kept
at the last in my list of probable things that can happen during an interview. Duration of
this round was around 90 minutes.
This time I had to face three technical questions and one general question on Amazon.
Question 1:
Given a BST, replace each node with the sum of the values of all the nodes that are greater
than that node. Only constraint being that I was not allowed to use any global or static
variable.
Although I panicked a bit and made few mistakes, I got through.
Question 2:
Given an array of numbers find the maximum count of duplets and triplets such that there
sum is a multiple of three. Number that has appeared once can’t be included anywhere else.
I solved this question using a property of modulus.
Question 3:
Given the stock prices of 10 days find the best possible buy sell pair.
For this question I started with a O(N2 ) solution but then finally managed to reduce it to
O(N) solution with constant space complexity.
I was also asked few questions on Amazon like what are domains in which Amazon deals.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-60-internship/
184
Chapter 64
185
Chapter 64. Set 61 (For Internship)
arr[]={3,6,2}
3+6-2 != 0
3-6-2 !=0
-3-6-2 !=0
-3-6+2 !=0
-3+6-2 !=0
-3+6+2 !=0
3-6+2 !=0
3+6+2 !=0
Hence ans= NO
2. Given a binary Tree where the structure of each node contains an extra “next” pointer
(initially all NULL), modify the binary tree such that all the nodes at the same level gets
connected by utilizing these given extra pointers.
The interviewer also asked me to write the code for the same.
Round 2 (Telephonic):
The duration of telephonic Conversation was about 90 minutes and the Interviewer asked
me 2 coding questions:
1. Write a code to find the Diameter of the given a binary tree
Firstly I gave the solution which has complexity O(n^2) then he asked me to optimize it so
finally I did it in O(n).
2. Given a number design the algorithm to find the next greater number which contains
exactly same digits. e.g. n= 123 next greater with same digits = 132
The number can be very large so its better to consider it as a sequence of characters.
I was also asked to write the code for the same.
I had a very great time preparing for the interview and got to learn a lot of new concepts.
I am really very thankful to GeeksForGeeks for being the primary source of my preparation
and believe me guys this website is just awesome.
And ya forgot to mention I finally got the confirmed offer for Internship at Amazon � �
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-61-internship/
186
Chapter 65
187
Chapter 65. Set 62 (For SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-set-62-for-sde-1/
188
Chapter 66
Source
https://www.geeksforgeeks.org/amazon-interview-set-63-sde-1-2/
189
Chapter 67
1. Given coin array and a sum K, find min. number of required coin to make sum K.
2. Two rectangles are given in two D space. Find if these are overlapping or not
3. KMP for pattern searching
After two days I got the call to come Amazon office for F2F interviews:
1st Round:
1. Program to construct binary tree from its inorder and preorder traversal. (algo+code)
2. Reverse every k-element in a linked list(algo+code)
2nd Round:
3rd Round:
1. Given a binary search tree of n nodes, find all the pair of nodes whose sum is equal
to a given number k in O(n) time and constant space.(algo+code)
2. Given a function “f” in which 0 occurs with probability 0.4 and 1 occurs with probabil-
ity 0.6. Using function “f” deduce a new function “f1” such that both 0 and 1 occurs
with probability 0.5
3. Given a matrtix, find the maximum sum subarray in it.(algo+code)
190
Chapter 67. Set 64 (Off-Campus for SDE)
In all the rounds, the most optimal production quality working code was required and if
you get stuck, then they will give you HINTS but don’t consider this in your favor!
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-64-campus-sde/
191
Chapter 68
192
Chapter 68. Set 65 (Off-Campus for SDE-2)
Source
https://www.geeksforgeeks.org/amazon-interview-set-65-off-campus-for-sde-2amazon-interview-set-65-campus-sde/
193
Chapter 69
194
Chapter 69. Set 66 (For SDE)
5. Any situation where you can see there are some improvements required and proposed
6. There is a large file( 1TB) containing braces. Question is to check for their balance. I
said will use a counter, will increment on an open brace and decrement on an close brace. If
counter goes negative or counter is non zero at the end of the file, braces are not balanced.
Otherwise balanced. Followup question was to make this process parallel (meaning to see
if this problem can be solved through parallelism, like dividing the the problem into sub
problem….) Remember the file is very large.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-66-for-sde/
195
Chapter 70
196
Chapter 70. Set 67 (For SDE-1)
6) F2F(SDE) He wanted me to build a boggle game. This is where I got a little mixed up
with some java and C# syntax and he was not too impressed. I tried to write the algorithm
using 2 for loops and he gave me some hints as to how to implement it.
7) F2F(SDE) Given a list of words, find anagrams. This was easy enough to implement. He
asked runtime in the end.
The interviewers communicated with you all the time, its not like you go in an exam and
quietly write what you have memorized. There is lots of pressure and lots of explaining to
do as you write the code.
All in all it was a great experience. The guys were cool and fun to interview with.
Geeksforgeeks was a tremendous help towards the interview.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-67-for-sde-1/
197
Chapter 71
198
Chapter 71. Set 68 (For SDE-1)
2. In a Binary tree, every element must contain the sum of its sub-trees
Follow up question: how would you solve this if you can ONLY increment the value of a
node
Eg. If a node’s value is 20 and its sub-tree sum is 10, the node’s value can’t be set to 10
because you can only increment
3. Given n, find the smallest number for which product of the digits is n, if no such number
exists, print -1
Note: Digits can only be split as single digits, i.e., 132 can’t considered as 1 * 32 or 13 * 2,
it would only be 1 * 3 * 2
Eg. Answer for 36 would be 49
Round 3:
1. Convert a Binary tree into another binary tree whose in-order traversal gives a sorted list
This has to be done in-place
Eg.
1
2 3
4 5 6 7
4
2 6
1 3 5 7
Source
https://www.geeksforgeeks.org/amazon-interview-set-68-for-sde-1/
199
Chapter 72
Telephonic Interview 1:
1. Sliding Window Problem: Given a larger integer buffer/array (say size, x), now given
a window size (say, n) and a number (say, k). Windows starts from the 1st element and
keeps shifting right by one element. The objective is to find the minimum k numbers
present in each window.
2. Given a binary tree, each node having an integer data, the objective is to create a new
Doubly Linked List using this binary such that each node in DLL has vertical sum
of nodes in binary tree. The order of nodes in DLL shall be left to right as that of
binary tree’s vertical nodes i.e., leftmost vertical sum shall be 1st node in DLL and
the rightmost vertical sum shall be the last node in DLL.
Telephonic Interview 2:
1. Given the root of the binary tree and a pointer to any random node in that tree, the
objective is to print all the nodes at ‘k’ distance from the given random node.
Face to Face:
Note: Time and space complexity were discussed in each of the following questions. And
for each question I was asked to optimize the algorithm and later write the working code
for it.Also in each round the current project was discussed.
Round 1:
200
Chapter 72. Set 69 (For SDE-1)
1. Given a matrix (m*n), source (0, 0) & destination (m-1, n-1) (i.e. last cell), Find out
total number of ways to reach the destination from the source.
2. Given a binary tree, defining a term “complete path sum” as, sum of values of nodes
lying in a path from root to the leaf; Now given a value ‘k’, we have to find the k-heavy
path and prune the binary tree i.e. prune/delete nodes for which complete path sum
is smaller than k.
1. Given two sorted arrays, create a final sorted array. Later, the problem was extended
saying that, now we have ‘m’ number of sorted arrays each of size ‘n’, now efficiently
create a final array. A lot of discussion was done on complexity of the approach (both
time and space).
Round 3:
1. Given a binary tree, where cost of travelling to the left child is ‘1’ and same for the
right child is ‘2’. Now, given the root of the tree and a value ‘k’, find the total number
of nodes that are at a distance/cost of ‘k’ from the root.
2. Given an unsorted integer (positive values only) array of size ‘n’, we can form a group
of two or three, the group should be such that the sum of all elements in that group
is a multiple of 3. Find the maximum number of groups that can be generated in this
way.
3. Given an integer array, find minimum number of jumps to reach the end of the array.
https://www.geeksforgeeks.org/minimum-number-of-jumps-to-reach-end-of-a-given-array/
Round 4:
1. Given a BST, convert it into a Doubly Linked List in place. NOTE: We don’t have to
create a new data structure i.e. we have to modify the links/pointers in given BST.
2. Question was framed this way: Given street of houses (a row of houses), each house
having some amount of money kept inside; now there is a thief who is going to steal
this money but he has a constraint/rule that he cannot steal/rob two adjacent houses.
Find the maximum money he can rob.
NOTE: I didn’t face any HR round, all though in each rounds I was asked about the reason
for the change.
In all it was a great experience, and interviewers were really cool and gave a plenty of time
to think and code, sometimes suggested/hinted if I got stuck.
GeeksforGeeks has been extremely helpful for me in preparing.
All Practice Problems for Amazon !
Maximum money
201
Chapter 72. Set 69 (For SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-set-69-sde-1/
202
Chapter 73
203
Chapter 73. Set 70 (On-Campus For Internship)
PI Round 1:
The interview started with discussions and questioning about the internship project and
other projects mentioned in my Resume.
After the discussions about projects interviewer asked a question on string the question
was:
Q1. A string of length n and an integer m was given, give an algo. to rotate the string
counter clockwise by m. I was asked to give all the check conditions for input m.
Then the interviewer asked me to write a code for the same with a strict guideline that there
should not be any mistake in the code ;).
Q2. After this he asked me about heap, min and max heap, insertion and deletion in a heap.
He asked me to prove that the time complexity of inserting n elements in a heap.
At-least he asked about the uses of heap data structure and other data structure which are
implemented using heap.
PI Round 2:
Q1) What is the difference b/w abstract and interface class?
Q2) Write a program to create single thread and print “Hello World”, stating all the argu-
ments of createThread function?
Q3) What is a deadlock and what are the condition necessary for the deadlock to occur?
Q4) What is a cache memory and how it is implemented?
Q5) Explain LRU, FIFO and other page replacement algorithms?
Q6) Write a code to implement LRU cache and then implement full cache memory?
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-70-on-campus/
204
Chapter 74
205
Chapter 74. Set 71 (For SDE-2)
Source
https://www.geeksforgeeks.org/amazon-interview-set-71-sde-2/
206
Chapter 75
207
Chapter 75. Set 72 (Off campus for SDE-1)
Q1. For a given number K, print all pairs of valid parenthesis combination and return the
total count of such combinations.
Q2. There are n balls kept on a table and connected in random fashion but there is no cycle
(no back edge). Write the code to select a ball such that after lifting the whole structure
from that ball height will be minimum. (algo+code+ mathematical proof of correctness)
Q3. Difference b/w http and https.
Q4. Suppose you are handling Amazon website and you have 10 MB size home page.
Optimize the homepage for a customer who has 100 kbps internet connection.
Further he asked for the customer who has 100 mbps internet connection.
F2F 3 (with Hiring manager, 80-90 minutes)
Lots of discussion about current project. He will ask you everything from bottom level to
your contribution.
Q1. Implement memcpy (*src,*target) function.
Q2. Reverse contents of a linked list.
Q3. I code in java so lots of question on oops and java like swing and awt difference , vector
and array list difference , interface and abstract classes.
Q4. Client and server code in chat window, background process in server and network,
networking layers.
Q5. Process and threads and code for thread safe situation (take an example and explain)
Bar raiser (Telephonic one hr)
Hr Question like biggest challenge so far, projects, why are you looking for a change, why
amazon, biggest mistake.
Q1. Given flat files (for an entire year, 1 per day) of train schedules (arrival and departure
times at a given station) find Min platforms required to accommodate the trains in that
station.(algo only)
Q2. I want to write a ransom note. But I don’t want to write it by hand, I’m going to cut
letters out of a magazine. How can I tell if the magazine has enough of the right words to
spell out the note I want to write? Let’s assume we have a way to digitize the text of the
magazine. (algo only )
I asked him about Amazon kindle and Amazon instant video. Show him that you know lot
about amazon.
Advice for Amazon: except from all data structure, read Trie data structure very well and
how to process big data.
Next day I got call from HR tht I am Hired � �
Thanks a lot to geeksforgeeks team.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-72-campus-sde-1/
208
Chapter 76
209
Chapter 76. Set 73 (For SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-set-73-for-sde-1/
210
Chapter 77
Set 74
eg 2, 1, -1, 0, 2, -1, -1
o/p: 1, -1
1, -1, 0
0
2, -1, -1
I did not clear after this round, I hope this helps others.
All Practice Problems for Amazon !
211
Chapter 77. Set 74
Source
https://www.geeksforgeeks.org/amazon-interview-set-74/
212
Chapter 78
213
Chapter 78. Set 75 (For SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-set-75-sde-1/
214
Chapter 79
215
Chapter 79. Set 76 (For SDE-1)
1
/ \
2 3
/ \ \ /
4 65
/ \
/ \ / \
7 8 9 10
Needed to connect the nodes vertically
1
/ | \
2 | 3
/ | \ | / | \
4 | 5 | 6
/ \ | / \ | / \
7 8 9 10
Assume each tree node has an additional pointer
(struct node* vertical)
Round 6 (F2F)
1. Given stock price of Amazon for some consecutive days. Need to find the maximum span
of each day’s stock price. Span is the amount of days before the given day where the stock
price is less than that of given day
2. Given a Binary tree each node should contain the sum of left and right subtrees. Leaf
nodes will become 0 in the resulting tree.
Round 7 (F2F with Project Development Manager)
1. Tell me something about yourself
2. Tell me about your previous company and projects
3. Why do you want to leave the previous company in such a small time.
Finally got the offer after few days �
Tips:- Be clear to the interviewer, the are quite helpful. Try to discuss the various approaches
that come up in your mind if you are struck somewhere.
All the best.!!
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-76-sde-1/
216
Chapter 80
217
Chapter 80. Set 77 (Off-Campus For SDE-1 / 1.5yrs experienced)
3rd f2f
Discussion about my projects (nearly 20 mins)
1. Given two numbers represented by two linked lists, write a function that returns sum list.
The sum list is linked list representation of addition of two input numbers. It is not allowed
to modify the lists. Also, not allowed to use explicit extra space.
2. Given a matrix of characters and a string, find whether the string can be obtained
from the matrix. From each character in the matrix, we can move up/down/right/left. for
example, if the matrix[3][4] is
o f a s
l l q w
z o w k
and the string is follow, then the function should return true.
4th f2f Hiring Manager
Deep discussion about my current project (nearly 45 mins)
(application architecture, challenges faced and a lot of technical discussion)
1. Write a program to check whether the given binary tree is BST.
5th f2f Bar Raiser
Deep discussion about my current project (challenges faced, etc) nearly 20 mins
Deep discussion on REST api authentications (Hash key vs Encryption & Decryption) nearly
20 mins
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-77-sde-1/
218
Chapter 81
Set 78
Eg : Input : teeterson
Output : r, as it is the first element which
is non repetitive.
2. Given a string of digits,find the next smallest number using the same digits.If its not
possible to get such a number print -1;
After a week, the results came out and 25 students were shortlisted.
Personal Interviews:
Technical Interview 1 :
1. Given an array of 1s followed by 0s,find the number of 0s.
219
Chapter 81. Set 78
I solved it by using Binary Search to find the first and last occurrence of 0 in the array and
subtracting the results.
2. Given an array of positive and negative numbers, find the pair of elements whose sum is
closest to 0.
Eg : Input : 3 5 -9 -4 17 11
Output 3 , -4
The brute force solution would be O(n^2) by comparing each pair of elements.As expected,
he asked me to optimize my solution.
So I sorted the array using merge sort. (I know its not in-place but it did not strike me at
the time)
Then used two indexes at the beginning and end of the the array and incre-
mented/decremented the indexes as needed.
3. Given a Binary Tree , print all the root to leaf paths.
I started by telling him my approach and the logic behind the recursive solution that I had
in mind. Then he asked me to write test cases for the function that I had written.
6 students were selected after this round.
Technical Interview 2
1. Given a binary tree convert it to a double linked list.
2. Given an array of integers , replace each element with the product of the remaining
elements.
Eg : Input - 1 2 3 4
Output : 24 12 8 6
First, i gave the obvious solution. I computed the product of the whole array and then
divided it by each element to get the resultant array.
But he asked me to do it without using the division operation. After some cross questioning
I gave the following solution.
Store the product of the left side elements for each integer in an array L[].
220
Chapter 81. Set 78
Here R[] = { 24 , 12 , 4 , 1}
Source
https://www.geeksforgeeks.org/amazon-interview-set-78-fresher-internship/
221
Chapter 82
222
Chapter 82. Set 79 (For SDE-1)
Interview 3:
Q1: Discussion about project in current company.
Q2: Given a shared memory between multiple threads, how will you ensure safe access to
memory in different scenarios like reading and writing? If at thr point of wrtitng there are
mutiple read requests from threads how pending requests can be managed.
Q3: Given an array that has positive numbers and negative numbers and zero in it. You
need to seperate the negative numbers and positive numbers in such a way that negative
numbers lies to left of zero and positive numbers to the right and the original order of
elements should be maintained
Interview 4:
Q1: Discussion about current project in company.
Q2: Why you want to leave your current company ?
Q3: Why Amazon ?
Q4: Which phone you have
Q5: Which one will you buy next
Q6: given a function with signature
bool isFactorialDivisible( int x, int y)
Return true if x! is divisible by y
else return false
After 3 days I got the confirmation call.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-79-sde-1/
223
Chapter 83
Set 80
224
Chapter 83. Set 80
2. Given a linked list which contains representation of any number, like for 1234, the
representation will be 1->2->3->4. Now we need to add 1 to the number, so that the
output is 1->2->3->5
3. Then he asked me 1-2 questions for which I immediately responded the solution, through
that he got the idea that I already know the solution
4. Moved to the white board, he draw a matrix, each contains only 0 ad 1 but in sorted
manner. I need to return the row which is having the max no of zeros. Then he asked me
optimized solution for finding the first ‘1’ in the array
5. Then he explained me a production line problem, Many factors were involved in that,
robotic arm need to draw some lines with various colors on some wall. We need to minimize
the cost of drawing those lines, Code was not required in that situation, as the problem set
was very big, but we discussed the complexity plus solving procedure for each of the factors
of the problem. Every minute detail of how will I solve the problem.
Basically problem itself was composed of many different types of sub problems, keeping
mind open at that time is very important.
Then after few days, I mailed the HR regarding the result, she told me one round is still
pending, will update soon and after 1-2 week, they sent the mail for halting the process,
didn’t get any solid reason, as it was totally unexpected, all my rounds went well.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-80/
225
Chapter 84
Eg 1 2 3
4 5 6
7 8 9
226
Chapter 84. Set 81 (For SDE-I)
Q2. Given a Binary Search Tree and two nodes find parent node which is parent of both
nodes in a given binary search tree. Later the they extended it to simple binary tree.
Round 4: F2F-I
Q1. Is given n-ary tree is Sum tree or not? implement function…
Q2. find Nth largest element in an array
Round 5: F2F-II
Q1. Vertical traversal Order of tree(implement it).
Q2. Lots of discussion on project.
Round 6: F2F-III
Q1. Given a circular array and a pointer find the given element in the array.
Q2. Lots of discussion on current company & company’s work.
Round 7: F2F-IV
Explain:
1. Customer Producer problem,
2. Semaphore
3. Deadlock how to solve it.
Q: Favorite Sorting Algorithm.why,where to use it? and various question on the sorting
algorithm which I answered.
Every time they ask for time complexity for code. Ask to optimize my solution.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-81-for-sde-i/
227
Chapter 85
228
Chapter 85. Set 82 (For SDE-2)
Source
https://www.geeksforgeeks.org/amazon-interview-set-82-for-sde-2/
229
Chapter 86
Set 83
Face to Face 1
• Design MP3 player which would play only unique songs in random order from given
list of songs
• Code : Print left and right most elements at all levels of a binary tree.
• Max elements in sliding window of size k over int array of size n.
Face to Face 2
Face to Face 3
230
Chapter 86. Set 83
Source
https://www.geeksforgeeks.org/amazon-interview-set-83/
231
Chapter 87
Set 84
232
Chapter 87. Set 84
d. What do to when you your hashmap is filled completely (as in all the linked list are
filled up to their capacity)
4. What is quicksort? Implement for a linked list and tell complexity.
Second Round :
1. What is quicksort?
a. What is complexity when all elements are sorted and how can you improve it?
(Randomization)
b. Will randomization work when elements are same?
c. What algorithms sort equal elements in O(n) time ?
d. using the information, how can you improve quick-sort? Think about it, its good.
Don’t want to spoil it for you by writing answer here.
e. implement this modification.
2. Given two river banks (visualization : two parallel lines), one bank has numbers written
(1….n) in sorted order. On the other bank the numbers (1…n) are arranged randomly. A
bridge can be formed from the ith point from bank 1 to ith point in bank 2. Find the max
number of non-intersecting bridges you can form?
3. Given 1…n , and given some statements like i hates j, then find some arrangement of n
numbers such that if i hates j then in the arrangement i comes before j. Say 1 hates 2, then
123456789 is acceptable but 213456789 is not.
4. Asked about internet. What happens when you type a URL on your browser?
Third Round (Hiring Manager):
1. Why do you want to leave current company?
2. Why do you think amazon is the right place for you?
3. Implement a calculator which takes a maths expression and evaluates it and prints the
result.
4. Given statements like A is connected to B. D is connected to E. And transitive connections
are allowed. Write a code which takes input such connected statements and and two numbers
i and j and returns true if i and j are connected (can be transitively), and false if not
connected.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-84/
233
Chapter 88
Set 85
1. Write a program to find longest repeating substring In a given string running code
were required covering all base cases.
2. U have given 10 files and you have given a string suggest data structure which ll
facilitate efficient search of string in the file if string appears more than ones in that
case u have to print line number and file in which they appear.
After 15 days I got cal that I have cleared the telephonic round and my F-2-F interview is
going to take place in Hyderabad
F-2-F round 1
After introduction and project related questions
1. Write a program to print a tree in vertical order asked more than one approach to do
this problem and modified problem many times.
234
Chapter 88. Set 85
2. Write a program to convert a tree to doubly link list in post-order fashion only change
of pointer are allowed that is left pointer can work as previous and right pointer s as
next.
1. Why amazon??
2. Why do u want to leave company XYZ.
3. Your biggest challenge till the date.
4. Many project related question.
Data structure
1. U have given 10 files each having 1 million integer in sorted order, physical memory
have size of 3 million suggest method to extract 1 million integer in sorted form
efficiently.
2. Write a program to convert a decimal number into binary your code should work
on both big endian and small endian machine. U have given a variable which tell u
whether machine is big endian or small endian
DBMS and few bar raiser question made this round average L
F-2-F round 3
1. You have given an n-ary tree write a program to check whether this tree is sum tree
or not.
2. Given an array write a program to find kth smallest element in the array. He was
hardly interested in the solution he just want to know how many ways u can solve it
solved using 5-6 method at the end he was satisfied with the answers.
F-2-F round 4
Longest one….this interview went on for 1 hour and 30 minutes but was interesting
one(interviewer looked lyk a frustrated guy…some tyms I felt that he is going to punch me
� :P)
1. You have given M array each of size n all array are sorted separately write a program
to make a big sorted array of size m*n . during discussion he told me to prove
many lemma like height of tree is log(n)( for n elements) sum of n natural number is
(n*n+1)/2 and many more. He modified problem many times don’t use extra space
do it in space etc. discussion went on for almost 1 hour but at the end he was happy
with the solutions(I suggested 2 method and further optimization in them.
235
Chapter 88. Set 85
2. U have given an binary matrix which is sorted row wise and column wise write a
program to search a row in the matrix having maximum number of zeroes.
Finally this interview also went well he was happy with my performance
After 2-3 days I got mail from the HR that I m rejected LL reason was bar raiser … 1 advise
to all don’t take BR round lightly it does not matter how well u performed in other round
if u didn’t do well in BR round then there is no way u can make it. An average round tech
interview is fine but average BR round means rejected.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-85/
236
Chapter 89
Set 86
237
Chapter 89. Set 86
these points, there a few special points from which you can directly jump to the diagonally
opposite point (Top-Right diagonal). You are granted a function which when invoked on
the point returns 1 if it is a special point and 0 if it is not.
2. You are given a sequence of black and white horses, and a set of k stables numbered 1 to
k. You have to accommodate the horses into the stables in such a way that the following
conditions are satisfied:
a. You fill the horses into the stables preserving the order of horses. For instance, you
cannot put for horse 1 into stable 2 and horse 2 into stable 1. You have to preserve the
ordering of horses.
b. No stable should be empty and No horse should be left unaccommodated.
c. Take the product (number of white horses * number of black horses) for each stable and
take the sum of all these products. This value should be the minimum among all possible
accommodation arrangements.
Round 4 (F2F with Hiring Manager):
1. Discussion on my current work, difficulties and challenges faced at work, difficult people
I have had to work with, instances when I went out of my way to propose creative solutions
to existing problems at work etc.
2. Given a parentheses string, determine if it is a valid / legitimate parentheses string. For
strings consisting of single parentheses type and those consisting of multiple types.
Round 5 (F2F – Bar Raiser):
1. Discussion on my current work, difficulties and challenges faced at work etc:-
2. Given a floor of dimensions 2 x W and tiles of dimensions 2 x 1, write code to find the
number of ways the floor can be tiled.
3. Given a graph, if we were to print all nodes within k hops of a given node, which algorithm
would we use, the answer to this was obviously a Breadth first search. He followed it up
asking, if one were to use Depth first search instead to code this problem instead, one would
encounter bloated running times for Graphs with certain attributes (Perhaps Dense graphs
or some such). Describe what types of graphs would a DFS algorithm falter with and why.
Round 6 (Telephonic Interview):
1. Given that you want to maintain a backend for a bookstore Application that would store
names of Authors and books, such that the application can return all the books written by
a specific Author and all the Authors of a specific book which is specified in a query. The
query can be such that only a substring of the Authorname or the bookname is specified
and all the matches should be returned. I proposed a trie based solution, and was asked to
code the solution on a collabedit shared document.
2. Describe multithreading.
3. Describe all the processes that happen between you typing in a URL and the webpage
appearing on your screen.
4. What is a singleton set What is the data storage model (Data structures) used to store
records in a relational Database.
5. Given an Array containing numbers between 1 to n, out of which 1 number is missing,
find the missing number.
238
Chapter 89. Set 86
6. Given a sorted Array and a number, print all pairs of numbers in the sorted Array that
sum to the given number.
I got the confirmation call the same evening that I had the telephonic interview. Geeks-
ForGeeks is a godsend for interview aspirants aiming at top companies. Keep
up the outstanding work guys, your website has shaped careers and lives. J
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-86/
239
Chapter 90
Example- Input 12 15 22 09 07 02 18 23 27
Output 15 22 27 18 18 18 23 27 -1
2) 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
240
Chapter 90. Set 87 (For SDE)
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() {
241
Chapter 90. Set 87 (For SDE)
1. What is your current project, What value you added in your project till now.
2. What challenges you faced while working in project and how did you overcome.
3. What was the important learning for you in last project.
4. If you have the option to go 3 year back in life, then what would you like to change
in life, means which skills and steps/decision you want to gain or change.
5. What you did in past on which you feel proud.. blaa blaa….
6. Given a tree, how will you find the vertical sum of nodes
refer this link to understand more about question
https://www.geeksforgeeks.org/vertical-sum-in-a-given-binary-tree/
I gave the solution using Hash map, but he was not satisfy with answer. He told to
gave other solution because Hash map will increase the space complexity. I used array
solution which was increase time complexity, then i used circular link list and finally
solve it using doubly link list. He was satisfy with solution. Told me to code for it.
242
Chapter 90. Set 87 (For SDE)
2. Explain inheritance and Base class is given you need to stop exposing the base class
methods without touching the base class at all. It was really tricky. question i liked
it.
3. What is deadlock and How to detect deadlock in system.
Source
https://www.geeksforgeeks.org/amazon-interview-set-86-sde/
243
Chapter 91
Set 88
1. Given a BST, transform it into sum tree where each node contains sum of all nodes
greater than that node.
2. Shuffle an array
Onsite F2F 1:
Started with general introduction , asked about my work , know any design patterns and
where you applied them in your project etc.
He asked a single question to design a single stack with push , pop and pop mid operations
, followed by working code.
F2F2:
Again started with general introduction , work i do , then he gave a question about finding
count of each occurrence of words in a document.
244
Chapter 91. Set 88
I gave hashing based solution (with working code), it lead to a great discussion on hashing
, then he led me to give a solution with tries . As much time is not left he asked me to tell
the approach only.
Some tips:
Source
https://www.geeksforgeeks.org/amazon-interview-set-88/
245
Chapter 92
Set 89
Ex:
1) 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7
Modified list:
6(7-1) -> 4(6-2) -> 2(5-3) ->0(4-4) -> 5 -> 6 -> 7
2) 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8
Modified List:
7 -> 5 -> 3 -> 1 -> 5 -> 6 -> 7 -> 8
246
Chapter 92. Set 89
/ \ / \ / \ / \
h i j k l m n o
Modified tree:
a
/ \
c b
/ \ / \
d e f g
/ \ / \ / \ / \
o n m l k j i h
247
Chapter 92. Set 89
• Replace BST nodes with the sum of nodes greater than or equal to the node.
Round 3 (Hiring Manager):
• Detailed discussion of my work in the current company.
• Some behavioural questions like how do you handle certain situations etc.
• Design a restaurant reservation system. I was also asked to write some sql queries in this
regard.
Round 4 (Bar Raiser):
• Given a linked list, write a function to reverse every k nodes (where k is an input to the
function).
• Given a sorted array which may contain duplicates, write a method to find the starting
and the ending index of the given number if present.
Suppose we are give array: 1,2,2,2,5,6,6,9,10,10,10
If the number given is 9 then starting index and the ending index will be 7.
If the number given is 2 then the starting index will be 1 and the ending index will be 3.
If the number given is 7 the the starting and the ending index will be -1 as the number is
not present in the array.
• Write a method to compress a given string “aabbbccc” to “a2b3c3” . It should be an
inplace compression, no extra space to be used.
• Discussion about my current project.
• Describe a scenario when you failed, when you helped our collegue etc etc.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-89/
248
Chapter 93
Set 90
249
Chapter 93. Set 90
Source
https://www.geeksforgeeks.org/amazon-interview-set-90/
250
Chapter 94
Set 91
1. Discussion around current company and work I was doing there. Why Amazon?
2. There is a robot standing at first cell of an M*N matrix. It can move only in two
directions, right and down. In how many ways, it can reach to the last cell i.e. (M,
N). Discuss all the approaches and then asked to code it.
3. Remove the nodes in the binary tree for that the sum of all values from root to leaf is
less than K.
Round 2: (F2F)
Round 3: (F2F)
Round 4: (F2F)
251
Chapter 94. Set 91
1. Given an array of size N= k*s. In this array, construct blocks of k size each (Number of
such blocks will be s). Now find all combinations of these numbers such that difference
among the k numbers in the block should not be greater than d. e.g. N=6, k=2, s=3
A={2,4,6,8} and d=2. So the answer should be 2 {{2,4},{6,8}},{{4,6},{6,8}}.
2. Given a binary tree with usual left and right pointers and one additional pointer called
adj. modify the tree in-place such that adj pointer should point to the right node in
same level as current node or if it there is no node right to it, adjshould be NULL.
Round 5: (F2F)
1. How many Binary Search trees can be constructed using sequence of N numbers?
Write Code for it.
2. How many cycles of length 3 can be constructed using edges of aundirected graph?
Source
https://www.geeksforgeeks.org/amazon-interview-set-91/
252
Chapter 95
Set 93
253
Chapter 95. Set 93
Source
https://www.geeksforgeeks.org/amazon-interview-set-93/
254
Chapter 96
255
Chapter 96. Set 95 (For SDE-I)
That means that you can not load the whole file into memory. How would you add these
two files and store the result in another file. Long discussion on optimization.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-95-sde/
256
Chapter 97
2) given few sets of intervals print out the the entire intervals without overlapping , if they
overlap then combine them into one.
Round 2 (F2F)
Tell me something about yourself.
1) Convert a BST into inorder, preorder and postorder linkedlists inplace.
2) Make a queue out of 2 stacks, as it was easy he asked me to code and asked me the
complexities.
3) Given a linked list with a loop find the loop and make it straight . I did with HashMap
but he told me not to use extra space so i told him floyd’s cycle.
He asked me i had any questions.
257
Chapter 97. Set 96 (On-Campus for Internship)
Source
https://www.geeksforgeeks.org/amazon-interview-set-96-campus-internship/
258
Chapter 98
259
Chapter 98. Set 97 (On-Campus for SDE1)
Source
https://www.geeksforgeeks.org/amazon-interview-set-97-campus-sde1/
260
Chapter 99
Set 98 (On-Campus)
261
Chapter 99. Set 98 (On-Campus)
Third Round(F2F):
Interview asked me to write the code for the two problems which are :
1.) Reverse the alternate K Nodes of the Linked List.
eg. 1->2->3->4->5->6->7->8->NULL
Result – 3->2->1->6->5->4->8->7->NULL.
2.) You are given the binary Tree and the two nodes say k1 and k2 . You need to determine
whether the two nodes are cousins of eachother or not.
eg. 6
/\
35
/\/\
7813
and say two node be 7 & 1. result will be TRUE.
say two nodes are 3 & 5. result will be FALSE.
say two nodes are 7 & 5. result will be FALSE.
3.) Give the algorithm, data structures, time complexity and space complexity for the
following problem :
In our mobile phones when we enter say four initials of the number say 9 4 5 6, then our
phone shows the whole lists of number that starts with these entered number.
Now the problem is : how it is implemented and what is the best way of doing this keeping
the balance between space and time complexity. Also, user can enter any number of initials
and your program should print all the numbers with those initials that are present in your
phonebook.
Fourth Round(F2F):
Interviewer asked some questions on C++ . They were :
1. What are virtual functions?
2. What is the use of virtual functions?
3. What are pure Virtual functions?
4. Syntaxes of Virtual functions and pure virtual functions?
5. What are abstract classes in C++?
6. How we can implement pure virtual functions in JAVA ?
Design question :
How we can restrict our class so that only single instance of it can be created?
What is Singleton Design Pattern?
Operating system Question :
1. What are semaphores?
2. What is producer consumer problem and give different solution for it?
Two questions he asked me to code :
1.Convert one string to another string.For that purpose you can use three operations –
SUBSTITUTE,DELETE,INSERT.Each having cost as one except
substitute having cost 2.You have to determine the minimum cost required.
For eg.
First String : INCLINE
Second String :DECLINE
Minimum cost required are : 4 [change I to D and N to E].
262
Chapter 99. Set 98 (On-Campus)
2. Implement the stack in which push(),pop() and getMiddle() has O(1) complexity at any
point of time.
3. Find the maximum size BST present in the binary tree.
He also asked question about my projects and why I choose them. He asked to just explain
the whole set of thing that I have performed in it.
(About 10 minutes discussion)
Fifth Round(F2F):
This round started with the deep discussion about my projects. Interviewer tried to get
each and every aspect of my project with lot many why
and how questions.She asked me the future scope of my project and what are learnings I
got from it.(About 30 minutes discussion).
Then she asked me implementation, algorithm, data structures, time complexity and space
complexity for the following problem:
Say we have website having several web-pages. And also there are lot many user who are
accessing the web-site.
say user 1 has access pattern : x->y->z->a->b->c->d->e->f
user 2 has access pattern : z->a->b->c->d
user 3 has access pattern : y->z->a->b->c->d
user 4 has access pattern : a->b->c->d
and list goes on for lot many users which are finite and numbered.
Now the question is we have to determine the top 3 most occurring k-Page-sequence.
for the above example result will be : (k=3) a->b->c , b->c->d , z->a->b.
[Question took the long discussion and she kept adding constraints, cases and more problems
to the above problem.]
One question she asked me to code which is:
You are given a sting. Find the character in that string which is not repeated and which
occur last in the sequence.
Eg.- aababaacdffgxc
Result – x
I would like to thanks GeeksForGeeks which helped me to improve my knowledge and
understanding of Data structures and Algorithms �
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-98-campus/
263
Chapter 100
Set 99 (On-Campus)
264
Chapter 100. Set 99 (On-Campus)
always give you hint and you have to think on that way.
2. GeeksforGeek
3. Always say interviewer what is your intrest subject.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-99-campus/
265
Chapter 101
266
Chapter 101. Set 100 (On-Campus)
A
/ \
B C
/ \
D E
/ / \
F G H
Convert the structure of the tree like a left aligned tree whose each node contains a down
pointer and a right pointer and looks like the below tree..
A
|
B – C
|
D—E
|
F—G – H
2.)The arrival and departure time of trains are given. Find the minimum number of plat-
forms to accommodate all the trains.
Round 2. (F2F)
1. An array is given in which elements are first monotonically increasing and then decreasing.
Search an element in the array. Working code was asked which takes care of all the edge
cases. Also asked the time complexity of the code.
2. Implement queue using 2 stacks .
What would be the complexity of enqueue and dequeue operation. I told him O(1) for
enqueue and O(n) for dequeue. Then he asked to optimize it. Then he asked the Average
case time complexity.
Round 3 (F2F)
1. You are given a graph. Write a function to remove all the cycles. Means after the function
call the graph must be converted into a connected acyclic graph(tree).
2. What happens when u send an email to someone.
3. What is socket ? What is port?
4. Which protocol is secure for mail transfer? Which protocol is used by Gmail?
267
Chapter 101. Set 100 (On-Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-set-100-campus/
268
Chapter 102
1. 20 MCQ’s
• Given a set of inputs (x,y) which represent intervals, merge overlapping intervals
e.x. (3,4) ; (2,5) ; (1,4) ; (8,9)
output should be – (1,5) ; (8,9)
*note – my code had errors, but as i had used merge sort for sorting the inputs, i
cleared the first round, whereas others with properly working code but in-efficient
algorithms didn’t
• Given a (nXm) matrix, with values present in each cell and a few in-accessible cells
marked as -1, find the path from (0,0) to (n,m) with highest sum.
2) Interview Round 1
269
Chapter 102. Set 101 (On-Campus)
2. Given a regular expression, and a string, validate the string against the regular expres-
sion
e.x.
Regular expression : ab*bbc*c
Pattern : abbbc VALID
Pattern : abc NOT VALID
3) Interview Round 2
1. A couple of questions from arrays, binary trees and BST’s , which were directly taken
from DS section of geeksforgeeks.
(I said I have coded them all and know the approach)
2. Box stacking problem for 2 dimension, 3 dimensions.
(I said I know the approach for all)
3. Box stacking problem for k dimensions
(I didn’t know the approach, so tried it out in the interview. Nearly reached the
solution, with the help of the interviewer. In the end, turns out, this was the same
question which was asked to him, during his interview round in amazon 2 years back.
“SET 2”)
4) Interview Round 3
1. Same question from interview round 1, given an array, find a pair with sum k.
But, now I was asked to optimize the solution to O(n) time.
2. Explain how chat-messenger functions in Facebook,Whatssap
3. Validate whether a given 9X9 matrix is a sudoku matrix or not.
(In all cases, the goal of this round was not to check your coding skills, but your ability
to handle all varieties of test cases!)
5) Interview Round 4
(This I believe, was probably a stress interview a.k.a Bar Raiser Round. The motive was
to shift your attention from one topic to another rapidly and see if you can handle the
questions that follow.)
270
Chapter 102. Set 101 (On-Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-set-101-campus/
271
Chapter 103
Set 102
272
Chapter 103. Set 102
2. Given a number you need to output the minimum number of factors needed to represent
that number such that none of the factors is divisible by a perfect square.
EX-
INPUT – 8
So number of factors of 8 (2*2*2 , 4*2 , 8) (NOTE : do not consider 1 because it is divisible
by all numbers) So minimum factor will be 1 (8) but it is divisible by 4 so not allowed then
minimum is 2(4 * 2) but again 4 is divisible by 4 so not allowed so finally answer is 3 (2*2*2)
OUTPUT – 3
You need to explain the logic of both the programs and then have to code both of them
2nd PI
General Introduction about myself and asked me my Weakness and strongness and again
once we were comfortable started asking questions
1. There are a number of houses in a row and each house contain some amount of money
in it. Now suppose you’re a thief and you want to steal money from this houses so
find the maximum money you can steal. Condition was that no two adjacent houses
can be robbed.
After doing this he asked me to also print the houses that were robbed
2. Given an expression consisting of opening and closing parentheses you need to find
the number of onions present in it.
Onion is any structure of the form ()
() – onion of size 1
(()) – onion of size 2
((())) – onion of size 3
So suppose if input is (()()) so output will be 2 because there are only two onions
present in it
Again Complete coding of the two functions was needed
Then he started asking questions on subjects – OS , Networking and a SQL query
3rd PI
Started with introduction and then he gave me question
273
Chapter 103. Set 102
OUTPUT – 01001110000011111110 (Number of 0’s and 1’s in the input and output
must be same so if you run out of any of them then just simple print the remaining
number)
1. Given a list of cities you can travel in an number of city now you need to find the
number of ways in which you can travel this cities.
2. Implement the pow function in logarithmic time.
3. Implement a DFA which will accept all string containing even number of 0’s and 1’s
4. Find the 2nd maximum number from a table using SQL query
5. Check whether a grammar is ambiguous or not
Source
https://www.geeksforgeeks.org/amazon-interview-set-102/
274
Chapter 104
2. Given a text txt[0..n-1] and a pattern pat[0..m-1], write a function search(char pat[], char
txt[]) that prints all occurrences of pat[] and its permutations (or anagrams) in txt[]. You
may assume that n > m.
Second day:
Round 2 : PI
1. Discussion on Project.
2. Code : Given an array of integers. Find the minimum distance between two numbers.
275
Chapter 104. Set 103 (On-Campus)
276
Chapter 104. Set 103 (On-Campus)
Round 6 : (Bar-Raiser)
1. Code : Convert little endian to big endian.
2. Code : Kth max in a file.
I did it using min-heap, then he sked me to use other data structure. Then I did it using
Balanced binary search tree.
3. Code : Find the second non-repeating character in a string.
4. Given prime number p>=5 :
Prove that : (p^2 – 1) will be divisible by 24.
5. Given a decimal number N as a string of digits (only 0’s, 1’s and 2’s are there), how do
I check if it’s divisible by 3 using regular expressions only, without converting to int? I was
asked to design DFA for that.
I would like to thanks GeeksForGeeks which helped me to improve my knowledge and
understanding of Data structures and Algorithms
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-103-campus/
277
Chapter 105
Set 104
Input:
abcdad (text)
abcd (pattern)
Output:
0, 1
1st technical:
1. Given a linked list reverse the even nodes in one pass and in O(1) space.
So 1->2->3->4->5->6->7->8 should be converted to 1->8->3->6->5->4->7->2.
2. Given an array containing integers, modify the array such that the 5’s are at the end and
the rest are at the beginning (maintaining the same order).
2nd technical:
1. 5 minute discussion about my OCR project.
2. Given an undirected graph, count the number of cycles with 3 nodes.
3. What is a spanning tree? Difference from tree, if any.
4. How to find the minimum spanning tree of a graph?
5. Given an array convert it to another array such that the following condition holds:
278
Chapter 105. Set 104
a < b > c < d > e < f > g < h where the modified array is {a,b,c,d,e,f,g,h} Input: 1,2,3,4,5,6
Output: 1,3,2,5,4,6 3rd technical:
1. What do you know about memory management in Operating Systems? What is segmen-
tation? What is paging?
2. Design problem: Given a station with n platforms. So each platform has one line. But
these n lines join into one, after leaving the platform (on both sides). Each train has to wait
a minimum of x minutes in the platform. Trains arrive from both ends. If all the platforms
are occupied they wait. There is also a point beyond the end of the platform (on both sides).
This point indicates that an incoming train has to wait at that point until a leaving train
(from that end) passes that point. Design the whole system.
3. How are big files stored in memory? What are the uses of B-tree? How is it more useful
than BST?
4. Given one billion file indexes and said that n files are missing. How would you identify
the file indexes of those who are missing?
4th technical:
1. Given an array of integers. This array denotes ‘our’ own ascending order of the elements.
So if the array is {2,3,1,4}, by mathematics we can say that 2<3<1<4. Given another array,
sort this new array in ‘our’ ascending order. Let’s say the new array is {1,2,4,3,5,4,9,2},
output will be {2,2,3,1,4,4,5,9}. Note that since 5 and 9 do not occur, they are sorted by
actual ascending order at the end. 2. Integers are coming in a stream. A special integer
(say -9999) denotes reset. Design a data structure such that when the special integer comes
the previous elements are printed in a zigzag way and all the elements are deleted (reset).
And then continues to accept other integers. What DS will you use?
Source
https://www.geeksforgeeks.org/amazon-interview-set-104/
279
Chapter 106
1. Merge overlapping intervals. This question has come many times so I am not repeating
it.
2. Given a singly linked list you have to subtract the value of first node from the last
node and so on until you reach the middle node.
280
Chapter 106. Set 105 (On-Campus)
281
Chapter 106. Set 105 (On-Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-set-105-campus/
282
Chapter 107
eg: 1->2->3->4
283
Chapter 107. Set 106 (On Campus for Internship)
| |
5->6 8
|
7
answer would be:
1->2->3->4->5->6->8->7.
2. Given a distance n. A person standing at position 0 has to reach n. He can either take 1
step or 2 steps at a time. In how many ways he can reach there.
Finally some definitions from OOPS, OS and basic data structures.
I was finally hired for the Internship at Amazon. I would like to thanks Geeks for Geeks
which helped me a lot in my preparation.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-106-campus-internship/
284
Chapter 108
F2F-2:
1) Brief discussion of work in current company
2) Find and print longest consecutive number sequence in a given sequence
Ex: Input: 1 2 5 3 6 8 7
Output: 5 6 7 8
3) A fair die is thrown k times. What is the probability of sum of k throws to be equal to
a number n?
F2F-3:
1) Brief discussion of work in current company. Why Amazon?
2) Why do you want to leave current company? What do you like most and dislike most
285
Chapter 108. Set 107 (For SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-set-107/
286
Chapter 109
287
Chapter 109. Set 108 (On-Campus)
so he asked me to give a schedule for above modules such that when a module is executed
then all requirements of that module are complete.
so answer would be D E C B A
2) Given a string of letters from alphabet. Remove all pairs(2 consecutive same character)
of characters which occur consecutively.And do it recursively on remaining string.
3) Given a string of letters from alphabet insert frequency of each character in the string.
288
Chapter 109. Set 108 (On-Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-set-108-campus/
289
Chapter 110
290
Chapter 110. Set 109 (On-Campus)
numbers will take a lot of time. He said you are getting close, then I suggested that we can
use a balanced binary search tree to store the pincodes along with indexes and then traverse
the bst in inorder fashion and swap the indices of the first pincode of file with the index of
inorder element. He was happy after hearing this and asked me to write the code and to be
careful with edge cases.
I did it.
Round 2 (CS Fundamentals)
He wanted to check my knowledge of DBMS, OS, and Computer Networks. Asked everything
related to these subject including all the layers of networks and from process-threads to
deadlocks to memory management in OS. Asked a SQL query to find 3rd maximum marks
of student from a database. I gave him 2 solutions � .
Asked me my favorite sorting algorithm. My favorite is insertion sort but I told him merge
sort because I knew a lot about merge sort so I wanted to drive the interview towards merge
sort and as expected he asked many questions on merge sort and I gave him all the answers.
He asked me to build a tree from given preorder and postorder traversal of tree, I said it
is impossible to build from only these 2 traversals , you have to give me inorder to build a
unique tree.
Round 3 (CS Fundamentals + Coding)
Deep discussion about project.
Asked me to choose my favorite subject other than any related to coding or algorithms. I
said Computer Networks. He asked why it is your favorite ? Why not OS or DBMS?
He asked me What happens when you type www.amazon.in in your browser. I was
expecting this question � . I knew this, told him everything.
See the links below for solution
http://igoro.com/archive/what-really-happens-when-you-navigate-to-a-url/
http://superuser.com/questions/31468/what-exactly-happens-when-you-browse-a-website-in-your-browser
http://edusagar.com/articles/view/70/What-happens-when-you-type-a-URL-in-browser
He asked me to solve a coding problem now.
Suppose I am given a sorted array of unknown size, then how will I search an element in
this array efficiently.
I said I can increase int i by the power of 2 and check whether the given arr[i] > element
to search whenever I find such element then I can apply binary search between i/2 and i.
He said this approach will work but what happens if while increasing i , you cross the array
length. Suppose an array is of size 6 , then your i will become 8 and arr[8] will give garbage
value so your program may go in an infinite loop. I said I can increase i in try block and
whenever this case occur then I can catch the exception in catch block where I will decrease
i by 1.
He smiled and asked me to write the code by taking care of edge cases.
Round 4 (Coding)
Deep discussion about the project which was on security. The interviewer asked me to
design the database of a chat application similar to whatsapp. I did it and said what
if some intruder access the database, then I said I will apply md5 encryption on phone
numbers, then he asked me how md5 works. Why only md5? He asked me what are Man
in the middle attacks and asked me to remove man in middle attacks from the message
transfers. He was impressed. �
He then asked me what is cache, why are cache fast and how it differs from RAM and hard
disk architecturally. This one was a bouncer, I hated computer architecture, admitted I am
291
Chapter 110. Set 109 (On-Campus)
a beginner in computer architecture. He laughed and said thank god, there is one thing in
which you are a beginner. I laughed too �
He moved further towards coding.
1. Suppose the structure of a binary tree is
Where random pointer points to any random node of the binary tree and can even point to
NULL, then how will you clone this tree.
This was the culprit question who led to my rejection.
I gave a lot of thought to it, but wasn’t able to solve it directly. I said we can use hash,
then he said what if there are duplicates in the tree then your hash will fail, then I said we
can convert the binary tree to doubly link list in place then clone the doubly link list, he
said ok but how will you generate the original tree from doubly link list, I never said it was
balanced. I gave a lot of thought here, nut yeah couldn’t solve it.
I got the solution by trying it after the interview, you can clone the left and right pointers
easily by traversing the tree and to clone the random pointers, you can apply this : newroot-
>random=oldroot->random; oldroot->random=newroot;
Then traverse new tree again and put newroot->random=newroot->random->random.
2. https://www.geeksforgeeks.org/find-the-row-with-maximum-number-1s/
I solved it efficiently.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-109-campus/
292
Chapter 111
2. Given a text txt[0..n-1] and a pattern pat[0..m-1], write a function search(char pat[], char
txt[]) that prints all occurrences of pat[] and its permutations (or anagrams) in txt[]. You
may assume that n > m.
293
Chapter 111. Set 110 (On-Campus)
Second day:
Suggestion: Always think loud when you are coding
Round 1 : PI 45 min
1. Discussion on Project.
2. Code : LCA of a BST.(check for all corner cases)
3. Code : LCA of a Binary Tree(check for corner cases)
4. Code : Maximum sum subarry along with its starting and ending index.
5. Code : Heap operations
Round 2 : PI (With Manager) 1 hr 15 min
1. Discussion on project.
2. Code : Given an array : A1[] = 2, 1, 2, 5, 7, 1, 9, 3, 6, 8, 8
A2[] = 2, 1, 8, 3
Sort A1 in such a way that the relative order among the elements will be same as those are
in A2. If the element is not present in A2, append them at last in sorted order.
o/p : 2, 2, 1, 1, 8, 8, 3, 5, 6, 7, 9
As I carried on telling him the approach, he went on modifying the question ( what if A2 is
much larger than A1 ?, what if they are of the same size ?)
A lot of discussion on complexities for all modifiactions. He was quite happy with my
answers.
Finally he asked me to code the O(nlogn) approach.
Round 3 (Subject Round) 1 hr
1. OS : Virtual Memeory (lot of discussion of its advantages, thrashing , etc)
Then he asked me design a LRU replacement policy(approach) which i did. Then he asked
to implement FIFO replacement policy with stacks. I did it using two stacks.
2. Neworking : He started with Transport Layer( discussion on ports. How data from
applications are changed into packets ?, etc).
Then he went to Network Layer (A lot of discussion on subnet masking and how it is used by
routers to map the IP address of incoming packet, how a Subnet is different from Internet).
Next we moved to Data Link Layer( Discussion MAC addresses, sliding window protocols,
etc).
3. DBMS: What is indexing?, Why indexing ?, How to implement indexing ?, What are the
different types of Index? .
Differences among Inner Join, Left Outer Join and Right Outer Join. He followed it up with
a SQL query on Outer Join.
As my first three rounds went very well, fourth round was of 15 minutes only.
Round 4 (Bar Raiser) 15 min.
1. Logical question. Given a prime number ‘p’. Prove that p^2-1 is always divisible by 24.
2. Find 2nd maximum element in a given array in one iteration.
All the best !
GeeksforGeeks has helped me throughout my preparation. This is the best site for clearing
your concepts on Data Structures and Algorithms. GeeksQuiz has helped me to get through
the MCQs in the online round. Thanks again !
294
Chapter 111. Set 110 (On-Campus)
Keep Smiling !
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-110-campus/
295
Chapter 112
1. About 10 minute discussion on my project on Cloud Platforms and Big Data Analysis
in Yahoo SDC. I asked him some doubts and he answered them clearly.
2. Given a string of digits, output all the dictionary words they can represent. (Basically
smart dial algorithm of an android phone). Each digit represents the corresponding
characters on a cellphone as follows.
296
Chapter 112. Set 111 (On-Campus)
e.g. : I/p : 3323 O/p : DEAD , DEAFFirst, he asked me how I would store the
dictionary. When he was satisfied by my approach, he asked me to write a recursive
function that would do the job if a dictionary is given as an input.
3. Then he gave me a class design. He went on changing his requirements and I was asked
to add support for them in my implementation. At first, his requirement was to draw a
rectangle and a circle. Then he went on adding requirements and finally it was to draw
different specializations (like curved-edges, skewed-edges, dashed-lines) of rectangles,
triangles and circle. He gave a constraint that support for a new specialization can be
added easily in my design.
2nd PI
1. Given, the starting and ending time of different meetings, what is the minimum number
of conference rooms that will be enough to accommodate all of them.He asked me to
code it.E.g, :
I/p : Meeting I – 8:30 – 12:50
Meeting II – 10:15 – 11:30
Meeting III – 11:45 – 1:30
O/p : 2
2. Implementation of a doubly-linked list using a single pointer. I didn’t know the answer
at that time. He gave me a few hints and I was able to solve it. Then he asked me to
code it.
3rd PI
1. Given an array of integers. This array denotes ‘our’ own ascending order of the
elements. So if the array is {2,3,1,4}, by mathematics we can say that 2<3<1<4.
297
Chapter 112. Set 111 (On-Campus)
Given another array, sort this new array in ‘our’ ascending order.
Let’s say the new array is {1,2,4,3,5,4,9,2}, output will be {2,2,3,1,4,4,5,9}. Note that
since 5 and 9 do not occur, they are sorted by actual ascending order at the end.
2. Return the left-view and right-view of an n-ary tree in a single traversal.
4th PI
1. Firstly, mugging up of codes will never take you far. If you find a problem that is
solved in geeksforgeeks, rather than blindly mugging up the code, read the description
properly. Try to understand what is being done and why is it being done. Try
to understand each and every line of code. It is naïve to expect common known
questions in interviews. But, if you can understand the approach of the codes solved
in geeksforgeeks, you can use it to solve a plethora of problems.
2. In an interview, always think out loud. Explain what you are doing and why you are
doing it. If you solve a problem within a few minutes without explaining your steps,
the interviewer will assume (perhaps not incorrectly), that you have mugged up the
code. This creates a very bad impression.
3. Follow proper etiquettes. Shake the interviewer’s hands while entering and while
leaving the room. Also, try to ask proper questions to the interviewer when he gives
you the chance to do so. These are the small things that set you apart from the other
interviewees.
4. Lastly, never be too tensed. Always remember, rejection is a part of life. Luck matters
a lot in job interviews. So don’t be disheartened if you are rejected. You can always
apply later.
Source
https://www.geeksforgeeks.org/amazon-interview-set-111-campus/
298
Chapter 113
2. There is a matrix mat[m][n] with entries as 0 or 1 When you are at 1 you can move in
all the eight directions and when at 0, you have to return back. Find the number of cluster
of 1’s
clusters ((0,0),(0,1),(1,0))
(1,2),(2,2),(2,3),(3,2)
(3,0)
Round 1:
1) Introduce yourself.
299
Chapter 113. Set 112 (On-Campus)
2) Any moment when you worked really really hard to solve a problem.
3) Find the best fit for a packet to be fitted in a rack rack sizes are given in increasing order
in other words find the ceil value of a key in sorted array.
4) Check given binary tree is BST or not
5) Find the lowest common ancestor in binary tree
6) If I have any question to ask him
Round 2:
1) Find largest sum contiguous subarray in goven array
2) If I had any question to ask him
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-112-campus/
300
Chapter 114
2. (Cluster Program) You are given a 2d matrix containing 0s and 1s. From a given position
in matrix, you can move in all the 8 directions i.e. (i+-1,j),(i,j+-1),(i+-1,j+-1). You have
to print the number of clusters of 1’s in the matrix. Two 1’s lie in a cluster if and only if
we can move directly from one 1 to another.
Input : m=5,n=5.
Mat[] = 1 1 0 0 0
0 1 0 0 1
1 0 0 1 1
0 0 0 0 0
1 0 1 0 1
Output : 5
First: (0,0),(0,1),(1,1),(2,0)
301
Chapter 114. Set 113 (On-Campus for Internship)
Second: (1,4),(2,3),(2,4)
Third: (4,0)
Fourth: (4,2)
Fifth: (4,4)
302
Chapter 114. Set 113 (On-Campus for Internship)
Source
https://www.geeksforgeeks.org/amazon-interview-set-113-campus-internship/
303
Chapter 115
while(scanf("(%d,%d),",&a,&b))
{
//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.
304
Chapter 115. Set 114 (On-Campus for Internship)
eg: -5,-2,5,2,4,7,1,8,0,-8
output: -5,5,-2,2,-8,4,7,1,8,0
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.
Person1:
ROUND 1:
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.
ROUND 2:
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 Program-
ming. 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
305
Chapter 115. Set 114 (On-Campus for Internship)
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.
Person 2
ROUND 1:
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
o/p 3->2->1->6->5->4->8->7
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.
eg. abcba
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.
ROUND 2:
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.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-114-campus-internship/
306
Chapter 116
307
Chapter 116. Set 115 (On-Campus)
1) Given n ropes of different length, combine them into a single rope,such that total cost is
minimum. You can tie two ropes at a time,and cost of tying is sum of length of ropes.
First i gave a solution similar to insertion sort in a linked list,he was not satisfied, and then
I gave a min heap approach. He asked for time complexity. I got wrong,so he asked what
steps u will do and time complexity for each step. He added all the step cost and asked me
to arrive at final time complexity.
After this, I got correct.
Then he asked about 2nd code in group fly activity.I used merge sort for it and he asked
why i had used merge sort,and asked to improve the code.
Then i gave a min heap solution (:P we discussed after group round). He asked me to code
it. I was not good at heaps. I tried my best but unable to arrive at working code
So finally he asked if i had any questions for him. I asked about amazon’s environment.After
this i thanked and left.
I was sure that i will be eliminated and i was eliminated.
Only 10 people went to 4th round and 3 people were hired finally.
Here are some mistakes done by me
It was first f2f for me and i was very nervous and had butterflies in stomach, which ultimately
decreased my performance.
I was not confident about the answer i gave.
My communication skills were very poor.
So try to avoid the mistakes done by me.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-115-on-campus/
308
Chapter 117
Round 3:-
Technical interview
18 people were selected for the next round and they asked me 2 questions
1. Given an infinitely growing sorted array which initially consists of 0’s and then 1’s upto
infinity. Find the transition point where 0 changes to 1 effectively.
2. Given a binary search tree, make 2 separate trees such that difference between the sum
of elements between them is minimum.(After some time he gave me a hint which helped me
solve the problem).
Round 4:-
Technical Interview
1. Some basic OS related questions
2. Implement a data structure which would perform insertion, deletion, search and random-
ize operation with minimum time complexity.
We discussed a lot of data structures and I settled with a data structure (Hashtable with
309
Chapter 117. Set 116 (On-Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-set-116-on-campus/
310
Chapter 118
311
Chapter 118. Set 117 (On-Campus for Internship)
ex : 1
/ \
2 3
/ \ / \
4 5 6 7
o/p : 4 2 6 5 1 3 7
6. Implement a stack using array. Implement two stacks using an array. Implement 3 stacks.
7. You are given an array . You have to create a stack when the user wants to do so
and delete a stack when the user says.You wont be given the number of stacks that will be
created.
I thank geeksforgeeks for providing an excellent platform to learn new things. Check the
interview corner for other company interviews.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-117-campus-internship/
312
Chapter 119
313
Chapter 119. Set 118 (On-Campus for Internship)
The interviewer introduced himself first and then asked me about myself.
We had a discussion on my projects.
1. Given two binary trees, write pseudo code to determine if one is a subtree of the other.
I answered it and then he modified the question to check if the other tree elements are the
subset of the elements of the first tree. (Hint: Inorder traversal)
2. Given a sorted circular linked list which is rotated at some point, write pseudo code to
insert a new node. Ex: 8 1 2 5 7 and insert 6.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-118-campus-internship/
314
Chapter 120
You are given n strings and you have to find their decimal representation. You have to print
315
Chapter 120. Set 119 (On-Campus for Internship)
Test Case 1:
5
Amazon
Microsoft
Facebook
Aa
Bb
Output:
642767638 microsoft
32232665 facebook
262966 amazon
22 aa
22 bb
Question 2: Given a string. Print all Possible permutations of different lengths in sorted
order.
Input: abc
Output:
A
Ab
Ac
Abc
b
Bc
c
Candidate who could solve at least one question out of 2 coding questions was selected for
personal Interviews.
Round 2(P.I. 1) :-
Firstly interviewer had a deep discussion of my project. He also asked me to write code for
one of my mini project (Backtracking).
Then he asked two back to back coding questions –
1. You are given a bst. You have to print the kth smallest element.
(https://www.geeksforgeeks.org/find-k-th-smallest-element-in-bst-order-statistics-in-bst/).
2. You are given two sorted arrays and you have to print the median obtained after merging
them in log(n) time complexity.
(https://www.geeksforgeeks.org/median-of-two-sorted-arrays/)
Then he asked the language in which I am comfortable for coding. I said C . Then he asked
316
Chapter 120. Set 119 (On-Campus for Internship)
me to allocate the dynamic memory of 2-d array in C( I used malloc function for this). Then
he asked me the difference b/w malloc and new (c++) function.
Round 2 (P.I. 2):-
Firstly he asked me to tell about my academic background. Then he directly put a coding
question in front of me.
1. You are given a binary tree and two nodes. You have to print the horizontal distance
between them.
Let us say :
Given nodes are B and C : Answer would be 2.
Given nodes are A and E : Answer would be 0.
Given nodes are D and G : Answer would be 4.
We had an long discussion of 45 mins (approx.) on this problem.
One of my friend was asked the following questions:
2. Given a linked list. You have to determine whether or not it is a palindrome in order
O(n) time without using auxiliary space.
3. You are given an array of integers . You have to find the maximum sum sequence.(It
needs not be contiguous).
After all these rounds I and my friend both were selected � :). A total of 16 candidates were
selected.
I really thank to GEEKSFORGEEKS for all the support and help in my preparation.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-119-campus-internship/
317
Chapter 121
5
Amazon
sun
run
Output:
262966 amazon
786 run
786 sun
318
Chapter 121. Set 120 (On-Campus for Internship)
she added that duplicates may be present but on left side only.
First she discussed for approach and then constrained the space complexity to be O(1). She
checked the code rigorously.
Then there were 3-4 coding questions. She just discussed approach.
-Update all nodes in a bst to be sum of all elements greater than or equal to it.
– Stock problem/ Given an array ‘arr’ find maximum difference between two elements
(max(arr[i]-arr[j]) where i>=j).
-Then there was this awesome question… Given a perfect binary tree.
print nodes in a specific manner. e.g-
15
/ \
13 14
/ \ / \
9 10 11 12
/ \ / \ / \ / \
1 2 3 4 5 6 7 8
print - 1 8 2 7 3 6 4 5 9 12 10 11 13 14 15
I told her approaches having some space complexity. Again she restricted space complexity,
and I got an efficient solution by recognizing some pattern � .
Round 2: 25 minutes
There were just two questions.
1- Given a string having no spaces, and a dictionary.Problem was to find if that string can
be splitted in multiple strings such that all the splitted
strings are in dictionary. I was provided a function search(string str) which will tell if a
particular string str is in the dictionary or not.
I quickly gave a recursive approach.
2- The second question was well known vertical order traversal of a binary tree. She just
discussed how to implement various approaches in C++.
Then there was discussion on types of projects assigned to Interns and blah blah.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-120-campus-internship/
319
Chapter 122
Source
https://www.geeksforgeeks.org/amazon-interview-set-121-campus-sde-1/
320
Chapter 123
Ex 2
/ \
-1 3
Output = 4
After this round 33 students were selected for face 2 face round. �
Round 1 F2F (40-50 mins)
Q1 – given a binary tree where the left subtree is mirror image of right subtree. So you have
to check whether the tree is symmetric or not (structure wise). O(n)
Ex - 1
/ \
2 3
321
Chapter 123. Set 122 (On-Campus for Internship)
\ /
4 5
Output - Yes
Q2 – given a sorted 2D matrix and you are given a value you have to search that value in
the matrix. I gave him two solutions. O(row + col)
Q3 – given two arrays in sorted form. The first array has some empty space equal to the
size of second array at its end. You have to merge both array in the smartest possible
way in the first array. With constraint that auxiliary space O(1).
Ex – arr1[9] = {2,4,5,7,8,_,_,_,_};
arr2[4] = {3,6,8,9};
after merging arr1 should be = {2,3,4,5,6,7,8,8,9};
For every question I was asked to write a working code with all corner cases handled. I
impressed the interviewer very much in this round :). Then I ask him some questions like –
how an intern contribute to the amazon’s claim to be the most customer centric company
and a few more.
I gave many approaches for this question but he was not satisfied with any approach. I
said I will try to do it in a binary tree then I will generalize it for n-ary tree. He said your
322
Chapter 123. Set 122 (On-Campus for Internship)
binary tree approach is correct but the way you are generalizing it to n-ary is wrong. The
interviewer gave me many hints and said you have almost solved the question but missing
a single point which I was not able to find till the end. Finally he moved to other question.
Q2- given a binary tree you have to check whether it is BST or not.
This question was very easy. I solved it within minutes (one inorder traversal approach
O(n)) but to my surprise the interviewer was saying it is wrong. I explained to him but
again he said it is wrong. His motive was to pressurize me but I stick with my solution and
finally he moved to other question. My answer was correct.
Q3 – given a BST find the Nth maximum and Nth minimum element.
I solved it in O(n). He was fine with it but he said do it in logarithmic time. I did it too
with some preprocessing and coded both the approaches.
Overall it was a very nice experience interviewing with them.
Some tips:
Source
https://www.geeksforgeeks.org/amazon-interview-set-122-campus-internship/
323
Chapter 124
Ex - 2
/ \
-1 3
Output = 4
324
Chapter 124. Set 123 (On-Campus for Internship)
2nd round :
Q1. Connect sibling pointer in a binary tree
https://www.geeksforgeeks.org/connect-nodes-at-same-level/
https://www.geeksforgeeks.org/connect-nodes-at-same-level-with-o1-extra-space/
Q2. Push ,pop and min operations in O(1)
https://www.geeksforgeeks.org/design-and-implement-special-stack-data-structure/
He asked me to do middle operation also and then he asked me to code 2nd problem.
https://www.geeksforgeeks.org/design-a-stack-with-find-middle-operation/
Q3. Given n point in a 2d plane ,find k distant nodes from the origin.
I told him min heap approach and he was satisfied.
Q4. Problem statement was very long but it was topological sorting.
https://www.geeksforgeeks.org/topological-sorting/
I used adjacency list representation, he asked me why
And finally asked me to code it.
Overall it was a very nice experience interviewing with them.
Some tips:
• Never give up
• Don’t start with coding ,first explain the approach.
• Be honest
• www.geeksforgeeks.org – my guidebook.
Source
https://www.geeksforgeeks.org/amazon-interview-set-123-campus-internship/
325
Chapter 125
326
Chapter 125. Set 124 (On-Campus)
asked.
“Find the kth element from the end in a SLL “
Different approaches were discussed and he asked me to code for the best one.
19 got shortlisted to next round.
Round 4:
It was one of toughest round for me. I was very much interested in SDE role but I was
interviewed for SE/QAE role. I dint dare to ask the interviewer about the role. We are not
said before the interview that they are going to interview for that roles. I mean it is in their
hands to decide the role that matches your skills.
Questions were a bit tough for me in this round because am not much good in troubleshoot-
ing and testing. And this round went almost for 1 hr 30 mins.
Questions:
1. Given start and finish times of a youtube video and how do you confirm that the video
is completely watched by the user or not? I gave a solution, we can set flags when the user
watches a particular unit of video. He asked me how discrete? I said it may be in terms of
seconds. He then asked me, If a user is just watching in terms of microseconds? I was not
able to give the right answer. He was not satisfied with my solution. �
2. A web application is running. We have only a text box. If we enter a name in the
text box, we get the details of the person whose name is entered. Now the question is to
troubleshoot the application when it stopped displaying the results after entering a name(
whose details are present in the data base).
I answered many points here, like server is disconnected and there may be locks on the
details such that only one user can access the data at a time. And many other, but he was
not much satisfied.
3. Give the test cases for the Gmail login page. At first I got tensed on hearing this question
but I answered well. I almost gave 10 test cases quickly but, the interviewer want to extract
as many he can. So he started noting down all the points which I said and kept asking me
further points. Finally 25 – 30 test cases were covered.
4. Given a video whose audio is not playing in a video player. Troubleshoot.
I gave many answers here. Like, there may be two major possibilities here. 1. The video
may have some problem 2. The video player software may have some problem. Then I gave
many points in each category. Like OS dependent etc. He was satisfied with my answers.
5. And 2 more questions were asked (I forgot ) They were from testing and troubleshooting.
14 got shortlisted to next round.
Round 5: (Hr + Tech )
This was the round which I dint get through. �
First, Tell me about yourself. I request everyone to be well prepared for this question in
any interview. It looks so simple, but its very difficult to impress the interviewer with your
answer here.
Next was a question from trees. Find the vertical sum in Binary tree. I said I’ve done it
before and I know the solution. He asked me to go ahead. Then I answered the same thing
which was given in GFG. He then asked me to do it in a single traversal. I gave another
solution but it also took 2 traversals. He scolded me that it is also taking 2 traversals. I
was not able to think anymore after this. But it was very simple one. ?
327
Chapter 125. Set 124 (On-Campus)
Next he asked me to find the duplicate chars in a infinite length stream of chars. I gave a
hashmap solution and he asked me about hashmaps. He then extended the question that we
have Integers also. Even then I said hashmap solution suits. He asked me about collisions
here. He asked me how much size of hashmap you need?. And also about the range of
elements that can be mapped? I answered well all these questions because I’ve read a lot
about hashmaps.
Next he asked me a troubleshooting question. I answered this like the one which I faced in
the previous round.
Next he asked me “what happens during withdrawal of cash from ATM “? (only during
withdrawal ?)
I was not able to convince him with my answers. He was expecting a lot in terms of internal
clocks and stuff in ATM.
Next He asked me “what happens when you enter an URL in a web Browser “?
I read this question in many interview experiences, so I answered it well But, He asked few
questions in between. Like what is HTTPS? What does ‘S’ stands for in ‘HTTPS’?
And finally I was in a trap by this final question. What is a Web server? I really don’t
know. But I dared to answer, But to my bad luck I answered DNS server instead of Web
server. He was very much angry with my answer and asked am bluffing? GONE �
All the impression was gone by just one simple mistake of mine and I dint get through.
Finally 9 people got offers out of 14.
2 were FTE and 7 were given INTERN.
TIPS:
If you are aiming for AMAZON then just try to solve as many questions as possible in GFG.
Try to be frank in the interview. If you don’t know the answer, Just accept that you don’t
know.
Finally be Strong. Rejections are inevitable unless you are very cautious.
I hope this will help others.
ALL THE BEST.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-124-campus/
328
Chapter 126
Round 1 F2F :
Q1- Two linked lists merge at one point, return the converging node. Constraint- O(1) space
and O(m+n) ,where m and n are lengths of lists.
Link: http://www.geeksforgeeks.org/write-a-function-to-get-the-intersection-point-of-two-
linked-lists/
Q2- Rotate the alternate levels of a binary tree.
329
Chapter 126. Set 125 (On-Campus for Internship)
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
/ / \ / \
8 11 10 12 13
Output:
1
/ \
3 2
/ \ / \
6 7 4 5
/ \ \ / \
13 12 8 11 10
First he asked to do it without recursion and then with recursion. O(n) time complexity.
Q3 – Write an efficient function that takes two strings as arguments and removes the second
string from first string (in place). (Shifting not allowed)
input:
str1: aabcabcb
str2: abc
output: ab
Q4 – Insert an element into a sorted link list which is having loop somewhere and duplicate
elements as well.
Q5 – Make your own data structure. which inserts, deletes and gives a random number in
O(1) time.
Hint : Use hash table and array.
Round 2 F2F :
Q1 – You have n pencils, each having l length. Each can write 4 kilometers. After writing
4 kilometers it has l/4 length. Then you can join 4 pencils which are having l/4 length and
can make 1 pencil. You can’t make pencil of pieces if remaining pieces are 3 or 2 or 1 in
number. And you can include these remaining pieces whenever you need. Write a recursive
relation independent of l,length of given pencil, for how much one can write from n pencils.
Write mathematical equation also.
Q2 – Find the largest sum subtree in a given Binary Tree.
Q3 – Reverse level order traversal.
time complexity : O(n)
Input:
1
/ \
330
Chapter 126. Set 125 (On-Campus for Internship)
2 3
/ \ / \
4 5 6 7
/ / \ / \
8 11 10 12 13
output:
13 12 11 10 8 7 6 5 4 3 2 1
You are permitted to use extra space and now print them in separate levels too.
Output:
13 12 11 10 8
7654
32
1
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-set-125-on-campus-for-internship/
331
Chapter 127
Round 1:
1. Print Matrix in spiral form.
2. A store have n customers and any 1 can visit them any time through out the year.Data
is stored in a file.Design a data structure to find given person visited on so n so date or not.
Round 2:
1.There are N packages P1, P2…Pn. A package may depend on another or many other for
its compilation. Given a matrix of dependency, find a sequence of package compilation.
2.A 2D matrix is given, with each elements representing number of gold coin at that position.
I have to travel from (0,0) to last element of matrix collecting maximum no. of coins.I can
travel either right of an element or down of it.
3.In Galaxy there are trillions of stars. I am provide distance of every star from earth. Tell
me nearest 1Million stars to earth, provided with best time and space complexity.
Round 3:
1. Implement LRU.
2.In Android phones we have 3X3 grid for making a pattern. Given a length, find number
of combinations for that length in that grid.
Round 4:
1. Project deep discussion.
2. Few given scenarios and how you will tackle.
332
Chapter 127. Set 126 (For SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-126-sde-1/
333
Chapter 128
334
Chapter 128. Set 127 (For Internship)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-126-internship/
335
Chapter 129
F2F-2:
1) Brief discussion of work in current company
2) A given array represents a tree in such a way that the array value gives the parent node
of that particular index.The value of the root node index would always be -1.Find the height
of the tree.
Ex: Array: 1 5 5 2 2 -1 3
5
336
Chapter 129. Set 128 (For SDET)
/ \
1 2
/ / \
0 3 4
/
6
I gave a iterative solution which was told to be optimized. I did optimize it using memo-
rization concept. I had to code it too.
3) Write a program to find the median of 2 sorted arrays when merged.
This problem is there in geeksforgeeks.
4)Write an optimised program to find the number of factors for a particular number
This was a very simple qn.
F2F-3:
1) Brief discussion of work in current company. Why Amazon?
2) Why do you want to leave current company? What do you like most and dislike most
about your current company?
3) Design a automation framework to test a simple site with a login page .Give the various
test cases also that should be considered. Later they told me to give some enhancements to
the code too.
4) Design a automation framework to test twitter api’s that is used in a particular site .
5)Give the various automation scripts and tools that I implemented in my current project.
F2F-4(Hiring Manager):
1) Lots of HR, behavioral and team fit questions
2) Describe the most challenging project I have worked on…and why is it challenging.
3) An e-commerce site has a particular functionality created by a group A and another
functionality created by group B. Design a testing framework that could test the work by
A as well as A/\B(intersection).
4) I was working as a security Analyst.So I was asked about 5 critical hacking techniques
that can be used to a e-commerce site and describe each.
F2F-5(Bar raiser):
1)Again behavioral and team fit questions.
2)Write a program to check the validity of sorting algorithms used to sort Linked
lists.Consider the case where 2 nodes have equal values too.
I gave a optimized code using hash table concept. The interviewer was pretty satisfied with
my coding ability and started asking me about my projects.
3)More questions on my projects
Thank you geeksforgeeks for helping me out during my preparation.
All Practice Problems for Amazon !
337
Chapter 129. Set 128 (For SDET)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-128-sdet/
338
Chapter 130
10
5 15
2 3 12 18
16 21
339
Chapter 130. Set 129 (For SDE 1 Off-Campus)
340
Chapter 130. Set 129 (For SDE 1 Off-Campus)
3. Tell me about a situation where you had a conflict with your manager and how you
resolved it ?
4. What is the biggest bug have you made ?
5. Have you developed any tool, which is used by your colleagues ?
6. Is there any task which you feel, that you could have done better in your project ?
7. Have you suggested any ideas and improvements to your project, beyond your call of
duty ?
8. Given a binary tree, write code to get the vertical sum of all the columns in the tree,
with minimum space complexity. After I told a solution with Hash, he asked me to come
up with a solution without using hash and code it.
Face to Face Interview 6 (Data structures)
1. Given a binary tree, how would you serialize it, store in a file and then recreates it again
from the file ?
2. Given a dataset below,
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-130-sde-1-campus/
341
Chapter 131
342
Chapter 131. Set 130 (For SDET 1)
then count the number of occurrences when there is a collision of two nodes in the same
cell.
Here the count is 1 because 5 and 6 occupy the same cell in the matrix
F2F 2:
1. Given a linked list, write a program to check if it is a palindrome
2. Write some test methods for stress testing of Furniture class
3. Some discussion on automation testing
Bar Raiser:
1. Given a singly linked list, write a recursive method to reverse every 3 nodes in the list.
I did not write a clean code for this. He moved on because of lack of time.
2. Again discussion of my current job role and about the projects I have worked on.
3. Tell me 3 things that you want to learn/change in yourself
4. Again several team fit questions.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-130-sdet-1/
343
Chapter 132
F2F 1:
1. Given an array of integers
you have to output sequence a1,a2,a3,a4,a5,a6,a7 such that a1a3a5a7
For example:
Given 10,20,30,40,50,60,70
You have to print 10, 30, 20, 50, 40, 70, 60
At first, I gave answer using sorting. But my interviewer asked me to do this without sorting
the input array, and I did it.
2. A simple question on Tree data structure which i don’t remember.
3. Questions related to my project.
F2F 2:
344
Chapter 132. Set 131 (For SDET 1)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-131-sdet-1/
345
Chapter 133
Example :
Input: -3 -2 6 0 7 -1 -8
Output: -3 6 -2 0 -1 7 -8
346
Chapter 133. Set 132 (For SDE Intern)
Input : 1->2->3->4->NULL
8->2->NULL
Output : 1->3->1->6->NULL
First he asked to do it without recursion and then with recursion.We also talked about
the problem we face if we store the value of the linked list in an integer or long if the
number of digits were above certain limits in the non-recursive function.
Round 2 F2F :(Duration – 1 hr)
Introduce Yourself.
Q1 – Find the largest subtree which is binary search tree in a given Binary Tree.
Then to optimise it and then asked me to code it.
Q2 – Given a linked list with a next pointer and an arbitrary pointer pointing to any node
in the list , copy the linked list.
After i gave him a solution which changed the links of the initial linked list, he asked me to
do without changing the links.
So i gave him a O(n^2) solution . He asked me to give another way or optimise my solu-
tion.He helped me to figure out the solution.
Hint – Hash map.
The interviewers were really helping and supporting and were more interested in seeing the
efforts you make and the way you get to the logic.They help throughout by giving hints.
Thank You geeksforgeeks for helping me out.
Best of luck .
All Practice Problems for Amazon !
347
Chapter 133. Set 132 (For SDE Intern)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-132-for-sde-intern/
348
Chapter 134
Set 133
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-133/
349
Chapter 135
2. Print all root to leaf paths using iterative algorithm in linear time.
Round 2:
1. Given ‘m’ and ‘n’ (m < n), print all nodes between levels ‘m’ and ‘n’ in level order.
2. Print a matrix in spiral order.
Round 3:
1. Check if two trees are mirror images of each other.
2. Given inorder and preorder traversals, build a binary search tree.
3. Print all the boundary nodes of a given binary tree.
I was rejected after this round. I applied again after few months.
Attempt 2
Written Round(on HackerRank): It contained 3 simple questions on data structures.
Duration 60 mins.
F2F – Round 1:
1. Given a singly linked list and a value ‘k’ such that kF2F – Round 2:
350
Chapter 135. Set 134 (Off-Campus for SDE)
1. Given a BST and given that 2 nodes are swapped in the tree. Identify the 2 swapped
nodes.
2. Given a BST and 2 nodes. Identify the length between the two nodes of the tree.
F2F – Round 3:
1. Detailed discussion of current projects.
2. How would you design the meeting invite feature of Microsoft Outlook? Considering
each meeting invite as an object and that Web server is the storage space for the invites,
design a data structure to receive and send invites to user in an efficient manner. The
message objects must be received in a sorted manner based on the time of meeting. I gave
an O(NlogN) solution and he was pretty impressed. I was then asked to code it.
3. An array is given whose every ith index is the child node of a[i] as shown in the example
below. The root node is represented by -1. Find the height of the tree.I did it in linear time.
Input: parent[] = {1 2 -1 2}
Output: 4
The given array represents following Binary Tree
2
/ \
1 3
/
0
F2F – Round 4:
1. Cultural info and projects discussion. What errors have you performed in your career
path? What are the major challenges that you faced?…and other such questions.
2. Design a parking lot system. She was very much concerned with all the edge cases.
3. How would detect whether a singly linked list is a palindrome or not?I gave a solution
with O(n) time and space complexity. But she asked to optimize it further with O(1) space
complexity.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-134-campus-sde/
351
Chapter 136
2. You have to find a string in two-dimensional array. The input contains 2-D array of
characters and given string. You can move in one of eight directions . The output contains
location of first letter of string if string found completely, otherwise return -1. Any one out
of multiple answers is accepted, if possible.
For example, Input:
btg
pad
rkj
String: rat
Output: (2,0)
352
Chapter 136. Set 135 (On-Campus for SDE)
F2F Round 1:
Brief introduction about myself and my project.
1. Given an array of positive and negative integers, rearrange positive and negative numbers
in 0(n) time .
First, I solved it using 2 arrays,each for positive and negative integers and place elements
of array in these 2 arrays and them combine them back by taking one element from each
array. Then he told me to do without extra space. I then segregated positive and negative
elements using quicksort .Below is the link:
https://www.geeksforgeeks.org/rearrange-positive-and-negative-numbers-publish/
2. Program to check whether strings are rotation of each other or not. I approached as below:
https://www.geeksforgeeks.org/a-program-to-check-if-strings-are-rotations-of-each-other-or-not/
He then told to solve without using strstr. I used naive searching method.
F2F Round 2 :
Brief introduction and some behavioral questions.
Given a BST and a key sum, design an algorithm to find all pairs of integers whose sum
equal to key.
I first approached using an array and placing elements into it in inorder fashion and then
find pairs. He told to do in-place and I solved with 2 traversals (inorder and reverse- inorder
).
F2F Round 3 :
Based on CS Fundamentals and also had 15 minutes discussion on my internship project.
1. What happens when we type amazon.com ?
2. Describe transaction process in detail if we want to transfer from one account to other.
Also design schema for it.
3. What happens on server side on receiving HTTP requests and how operating system
interacts and then discussion related with threading, thread pool ,synchronization, hashing
etc.
4. Describe ACID properties in detail .
Bar Raiser Round :
1. Given a Binary tree, full_path_sum is sum of all nodes from root to leaf in a path. Given
a min_sum value, delete nodes if path has full_path_sum less than min_sum . Delete all
such nodes . For example,
Given min_sum =8
1
2 3
4 5 6 7
So we delete 4.
353
Chapter 136. Set 135 (On-Campus for SDE)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-135-campus-sde/
354
Chapter 137
For example:
102 - 152
1020 - 1525
(Do not use any array for replacing the '0' to '5')
3. You are given two binary tree and write algorithm to check
Are two Binary Trees mirror image of each other?
Amazon Interview for SDET @ Hydrabad Development Center
******************************************************************************
1st Round
************
1. Project Detail & past experience
2. Current Technology i am working in
3. https://www.geeksforgeeks.org/intersection-of-two-sorted-linked-lists/
4. Maximum Subsequent distinct & contiguous sub array in a character array
2nd Round
**************
This round was purely for checking Test Framework and Test Case Knowledge.
355
Chapter 137. Set 136 (For SDE-T)
He has given me some scenario and ask to write test cases for them
1. you are given a web page into that simply one browse button and Image Holder is
their.Write the Test Cases for this.
2. You are given application like Google Analytics. How will you test this application ?
3. what are the basic features you will add into your own test framework.
3rd Round
*************
This round was purely a discussion based on past project experience.Like which project do
you think that was most difficult and you had a nice experience.
He asked me each progress point of the project.
1. how will you check that each page of amazon.com is having its logo or not.he also asked
me to write code for this also.
2. Some Test Framework Based question like
3. Have you worked on any automation framework or not?
4. what happen between, when you enter a URL into a browser address bar and hit enter
to actually page gets loaded ?
In between he asked me few things about DNS Server,Router etc and some discussion was
there.
4th Round
*************
1. https://www.geeksforgeeks.org/level-order-tree-traversal/
2. https://www.geeksforgeeks.org/reverse-level-order-traversal/
3. Make a stack using 2 given queue.
4. Some Project Experience & Automation Framework Discussion,which i have worked on.
5. There was some situational questions also for Team work.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-136-sde-t/
356
Chapter 138
Amazon interview Experience | Set 137 (Assessment test for SDE) - GeeksforGeeks
Coding questions:
1) Given two words, find if second word is the round rotation of first word.
For example: abc, cab
return 1
since cab is round rotation of abc
Example2: ab, aa
return -1
since aa is not round rotation for aa
2) Given two hexadecimal numbers find if they can be consecutive in gray code
For example: 10001000, 10001001
return 1
since they are successive in gray code
Example2: 10001000, 10011001
return -1
since they are not successive in gray code.
Aptitude questions:
1) Some based on finding relationships between given number/strings and find the missing
one
Example: VTS: RPO :: AYX: ____
2) Paragraph reading and inferring information from it.
3) Facts provided and making a decision based on it.
4) Combinations possible based on facts provided.
All Practice Problems for Amazon !
357
Chapter 138. Set 137 (Assessment test for SDE)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-137-assessment-test-sde/
358
Chapter 139
Round-4
359
Chapter 139. Set 138 (For SDE 1)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-138-sde-1/
360
Chapter 140
Set 139
361
Chapter 140. Set 139
the numbers that do not appear in the second array, sort according to face value. Discussed
methods and codes. He always pushed to optimize the code.
This was followed by discussion on sorting techniques, there comparisons. In the end he
asked a few questions from OS mainly the scheduling algorithms.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-139/
362
Chapter 141
http://stackoverflow.com/questions/3757393/given-a-number-p-find-two-elements-in-array-
whose-product-p
2. He asked do I know level order traversal of binary tree. He ask me to code then, he
changed the question and asked about spiral order traversal of binary Tree and asked me to
code it.
https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/
2nd Round (Telephonic):
1. In a BST two nodes were swapped. Given the pointer to root node find the two nodes
and rectify the tree. He asked the approach then asked me to code the same in collabedit.
https://www.geeksforgeeks.org/fix-two-swapped-nodes-of-bst/
2. Given an integer array, find and print three element in the array whose product is
maximum. Code was required.
http://www.technicalypto.com/2010/05/find-three-numbers-in-array-which-forms.html
3rd Round (face2face onsite)
1. Given a sorted array of n integers, count and display number of triplets such that a[i] <
a[j] < a[k] 0(n) time. Code was required.
2. In a given string some of the characters are replaced by question mark, and you can replace
question mark with any character. Given such a string find total number of palindrome
that can created. String contains only [a-z] characters and question marks can also be only
replaced by [a-z]. Example: Input String: String str=”a??a” Output: 26
363
Chapter 141. Set 140 (Experienced for SDE)
3. Given a binary tree all the leaf nodes in the form of a doubly linked list. Find the height
of the tree.
4th Round (Hiring Manager Round):
Detailed discussion about previous company work?
Why I want to leave my previous employer?
Why Amazon?
What if I don’t like the work?
What are challenges I have faced in my work, how I resolved it?
Weakness and strength?
What does router do, what is static routing? Given a routing table, how would you decrease
the time taken by router to decide to which router packet must be forwarded?
Details of algorithm that could be implemented and discussion time and space complexities.
5Th Round (Face2Face Onsite):
1. Given N sorted LinkList of different length, merge them into a single sorted link list.
Pseudo code was required.
2. Given a number d and size of array N. Print all combination of element in the array such
that first element of array is d and next element in the array can be +1 or -1 the previous
element in the array. Code was required.
3. What is LRU and implementation of lru? Write pseudo code for the same.
I would like to thanks GeeksforGeeks for providing us such a learning platform.
All Practice Problems for Amazon !
364
Chapter 141. Set 140 (Experienced for SDE)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-140-experienced-sde/
365
Chapter 142
366
Chapter 142. Set 141 (For SDE1)
5. words are coming through a stream , u have to halt the problem when first repeated
words appear.
Used trie data structure.
6. N words are given.u have one source word and one destination word .u have reach to
destination in minimum edit with the constraint that intermediate word should be from
the words given.i have given the solution using graph and used BFS traversal .complexity
discussion
7. what happen when u hit url .I have tried to explain it using Django, he is expecting
something from domain name server. Be prepared
Complexity concept should be clear(Recursive+iterative both)
Other than this a lot of question on my company project and my performance rating. expe-
rience of professional life.
Should know each and every single word of resume.
Good luck
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-141-sde1/
367
Chapter 143
1. Insert a crate
2. Search the best fit crate
3. Delete the crate after allocating it.
e.g. 3 crates of weight 10, 20 and 30 are there. An item of size 15 appears then we’ll allocate
crate of size 20 and delete it.
Sol. Use binary search tree (balanced using red-black criteria or any) and implement ceil
function.
All operations will be O (log(n)).
Q2. Optimize above data structure for weekends where amazon have lots of crates but very
less search operations.
368
Chapter 143. Set 142 (Off-Campus for SDE-1)
Q3. Given a function boolisValidWord(string str) you need to check whether a string is a
proper string or not. E.g. iloveicecream is valid : I love ice cream.
Round 3: Manager of some other Team
Deep discussion on projects.
In one project I used EC2 service so he asked me many details and why I preferred EC2
over other possible options.
Buy and sell stock question.
https://www.geeksforgeeks.org/stock-buy-sell/
https://www.geeksforgeeks.org/connect-nodes-at-same-level/
General discussion on virtual memory.
Round 4: 2 SDE-1s
Q1. Given matrix of 1s and 0s where 0 is water and 1 is land. Find number of islands.
Q2. Give the size of all islands in above question.
Q3. https://www.geeksforgeeks.org/maximum-of-all-subarrays-of-size-k/
Round 5: Dev Manager, 6yrs exp. (May be bar raiser round still I am not sure :P)
Q1. We started our discussion for very general problem where we have a long stream of
characters and we need to extract all the patters from that stream. There can be integers,
fractions, words or anything.
I explained the entire process which is used in lexical analysis phase of compiler design where
we give regular expressions and finally they are converted to NFAs and finally a single DFA.
Then a discussion went on how we’ll implement this system from scratch.
There are many algorithms for converting regular expressions to NFAs and finally DFAs and
some general discussion over Natural Language Processing.
http://algs4.cs.princeton.edu/54regexp/
Q2. Given M sorted linked lists of each of size N, we need to merge them to single linked
list of size M x N using no extra space.
Next day I got the call that they would like to extend me the offer for SDE-1 profile.
Important Tips:
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-142-campus-sde-1/
369
Chapter 144
370
Chapter 144. Set 143 (Off-Campus for SDE-1)
I would like to thanks GeeksforGeeks for providing us such a useful platform for interview
Preparation.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-143-campus-sde-1/
371
Chapter 145
372
Chapter 145. Set 144 (Off-Campus For SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-144-campus-sde-1/
373
Chapter 146
list1: 1->2->3->4
list2: 5->6->7
o/p list: 1->5->2->6->3->7->4
2-> Given two trees T1 and T2. WAP to check whether T1 is a subtree of T2 or T2 is a
subtree of T1
3-> WAP to find maximum sum sub-matrix from a give matrix.
Round 1:
1->You are given a sorted but rotated array of integer like: 6 7 8 1 2 3 4 5
You have to search an element…
I answered with an O(logn) solution…
then he asked me to write the code…
2->What is the diameter of a tree?
I answered…
then he asked me to write the complete code…
3->He asked me a design problem “you have to design a class “DeckofCards”…with 2 oper-
ations: 1:Shuffle 2:Pick”
Pick would pick a random card from the deck and Shuffle will shuffle the cards and give you
back the deck of cards.
374
Chapter 146. Set 145 (Off-Campus)
I answered with 2 options 1.LinkedList 2:Array…then there was a discussion around 15 mins
over both the solutions…
Round 2:(I guess it was the bar-raiser round)
1-> My Introduction and My Projects (all 1 by 1 except the last)
2-> How to compute all possible solution of A^3+B^3=C^3, where A,B,C belongs to (0 to
N)?
Write code…
3-> How to compute A^n where n<1 million Write code... 4-> A tough “matrix with a
mask” problem…I took around 20 mins to solve it.
5-> Why Amazon, what is scalability and questions from my answers…like how would you
manage millions of requests…
Round 3:
1-> You r given a matrix of 0s and 1s. WAP that check if an element is 0 or not and places
zeros to all the col and row of that element.
2-> How to find a largest palindrome from a given string? Write code….
3-> How many Data Structures you have implemented by yourself?
4-> Given some words(written in lexical order) of some unknown language…You have to
find lexical ordering of all the alphabets…
Like in english lexical ordering is A B C…Z
Round 4
Forth round was just related to my projects and subjects…(Paging, Deadlock, Trashing,
JAVA and C, Synchronization, etc) + 1 final algo question “How to find all anagrams in a
dictionary” Solution was in O(1)..
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-145-campus/
375
Chapter 147
Set 146
376
Chapter 147. Set 146
Sub questions:
* Provide a solution, optimize it, give a working code or pseudo code or an algorithm for
the same.
Question 1: Given two valid dictionary words, find the minimum number of steps required
to transform first word to second word. Following are the transformation rules –
1. You can, in a single step, change a single letter in the word.
2. Each transition should result in a valid word. Assume you have been provided a helper
function boolean isValid (String word) which tells you if a word is valid or not.
3. This must be done with minimum transitions.
Example: Transform CAT to TOY. One of the several possible transformations is CAT ->
CAR -> TAR -> TOR -> TOY
Question 2 : Assume you have been given a binary tree such that the angle between
horizontal and the line joining node to it’s left child (or right child) is 45 degree. This
essentially means node 5 and 6 in the tree figure above collapse into a single node. A
vertical for a tree is defined as shown in the figure below. Given a binary tree of the kind
defined above, find the number of verticals that can be drawn.
Example: Refer to the diagram below to get an idea on verticals.
377
Chapter 147. Set 146
?
Sub questions:
* Provide a solution and also provide a working code for the same.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-questions-set-146/
378
Chapter 148
Set 147
379
Chapter 148. Set 147
2. A big unsorted array of numbers are given.Each number is big of almost 10bits.How to
sort these numbers?
Ans-Counting sort
3- An Adjacency matrix is given which is represented by 2d array.and each field is having
cost associated.You are also given source and destination points.Find the maximum cost to
reach from source to destination.
Face to Face 3
1. Discussion on work in my current company.
2. What is memory corruption,stack overflow,memory not available.
3. what is difference between multiprocessing and multithreading? Do all threads of one
process is having there own code,bss,stack and heap or it is common for all.
4. what is Tail recursion.How tail recursion works.
5. Can we overload a function by only changing its return type?
6. How virtual table works and lots of c++ concepts.
Face to Face 4 (With Manager)
1. Tell me about yourself.
2. What is the most challenging condition you have tackled in your life.
3. What you will do if you have conflict with your manager.
4. Guys this question brainf**cked me.The question was based on “20 question game”.I
never played this game. This was the actual question-
380
Chapter 148. Set 147
Source
https://www.geeksforgeeks.org/amazon-interview-questions-set-147/
381
Chapter 149
Set 148
e.g.
1 1 1 0 0 0
1 1 0 0 0 0
1 1 1 1 1 1
1 1 1 0 0 0
1 1 1 1 0 0
2. How to find two sets(of size m,n) are dis-joint(have no elements common) efficiently
A: Use hash map. Complexity is O(n) in worst case.
Follow up Q: How are hash maps stored in memory?
All Practice Problems for Amazon !
382
Chapter 149. Set 148
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-148/
383
Chapter 150
384
Chapter 150. Set 149 (On-Campus for Internship)
You are given n strings and you have to find their decimal representation. You have to print
the string and corresponding decimal representation in descending order. For example, if
you are given “amazon” then its corresponding decimal notation will be 262966. If more
than one strings have same decimal notation then you have to print them in the order in
which input is given. The given string consists of lower case alphabets only.
Test Case 1:
5
Amazon
Microsoft
Facebook
Aa
Bb
Output:
642767638 microsoft
32232665 facebook
262966 amazon
22 aa
22 bb
385
Chapter 150. Set 149 (On-Campus for Internship)
Example:
Inputs: 1->2->3->4->5->6->7->8 and k = 3
Output: 3->2->1->6->5->4->8->7
Q2. Given an array arr[] of integers, find out the maximum difference between any two
elements such that larger element appears after the smaller number in arr[]. Print the
indices of the two elements also.
Example: If array is [2, 3, 10, 6, 4, 8, 1] then returned value should be 8 (difference between
10 and 2). If array is [ 7, 9, 5, 6, 3, 2 ] then returned value should be 2 (difference between
7 and 9).
Round 3 (Face to Face):
There was brief introduction. Then he asked some questions from my resume. He asked me
to tell about a project which I loved the most and felt proud after doing it successfully. He
was interested in knowing the details of the implementation in that project.
After that there were 2 coding questions:
Q1. Given a string, find the longest substring without repeating characters. For example, the
longest substrings without repeating characters for “ABDEFGABEF” are “BDEFGA” and
“DEFGAB”.
Q2. Given a log file of page visits of a website by different users for a day.
Entry in the log file is like this:
User 1 visited Page 4
User 3 visited Page 2
User 7 visited Page 9
.
.
.
Design an efficient data structure which supports queries like the following:
Which page was visited by exactly 2 users in day?
Which page was visited by only one user exactly 2 times in a day?
Which page was visited by ‘User 3? more than 5 times in a day?
In 2nd and 3rd round, we had to write code on paper.
The overall interview experience was quite good. They wanted the most optimal solutions
and gave hints to think in that direction.
I was finally selected �
Tips:
386
Chapter 150. Set 149 (On-Campus for Internship)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-149-campus-internship/
387
Chapter 151
Amazon Interview Experience | Set 150 (SDE1 for 1 Year Experienced) - GeeksforGeeks
Telephonic:
1. http://www.geeksforgeeks.org/write-c-code-to-determine-if-two-trees-are-identical/
2. http://www.geeksforgeeks.org/convert-a-given-tree-to-sum-tree/
Round 1
1. https://www.geeksforgeeks.org/print-left-view-binary-tree/
2. http://www.geeksforgeeks.org/find-a-peak-in-a-given-array/
Round 2
388
Chapter 151. Set 150 (SDE1 for 1 Year Experienced)
Think out loud all the time (so that even when questions are easy they will catch your
thinking with greater importance)
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-150-sde1-1-year-experienced/
389
Chapter 152
Example :
1 27
/ \ / \
2 3 -------> 9 13
/ \ / \ / \ / \
4 5 6 7 0 0 0 0
390
Chapter 152. Set 151 (For SDE)
For all the questions, complexity of the program was asked and was being asked to improve
both time and space complexity.
F2F 2
Many questions regarding my current project, tools and technology I am working on.
1. Convert a binary tree to a sum tree . Here he had a new meaning of sum tree.
Example :
Example :
1 1
/ \ / \
2 3 -------> 2 5
/ \ / \ / \ / \
4 5 6 7 4 9 15 22
(I did it with Level Order Traversal) (Complete working code was required)
2. Given an array of integers. Find the largest 3 element. (Can be done using Max Heap in
less time complexity)
F2F 3
Lots of questions on my current work and tools which I was using.
Why do I want to leave my current company on such a short interval of 5 months.
Why Amazon ?
What inspires you to join Amazon? Why dream company ?
1. Connect Sibling pointers. I gave a Level Order Traversal solution. He asked to do it
in O(1) space complexity. I explained the approach but messed up In writing the working
code for that.
2. Explain the approach of LRU cache and implement using object oriented language.
F2F 4
Why Amazon?
Why do you want to leave your current company in such a short interval?
Did u ask your current company to provide that type of work as u r looking in Amazon?
1. Design a system for finding the costliest element always whenever we pick up an element
from a box.(concept of Max Heap)
2. A stream of data is coming. Maintain records in a page and mechanism to see previous
and next page. (Concept of Doubly Linked List)
(It is always advisable to ask questions in design questions. The interviewers expect that
we will be asking questions for clarification)
What is thread?
What is the meaning of memory leakage?
Followed by many OS questions but I forgot.
In every round , after each question , complexity of the algorithm was asked. Its good to
ask questions to get more clarification about the question.
I want to thank the entire team of geeksforgeeks. It is a great portal and it helped me a lot
in preparing for Amazon interview.
Reference – GeeksForGeeks and Cracking The Coding Interview
All Practice Problems for Amazon !
391
Chapter 152. Set 151 (For SDE)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-151-sde/
392
Chapter 153
393
Chapter 153. Set 152 (Kindle Team SDE-1 )
They discussed for all this 4 questions and why I choose to write this answer, some modifi-
cation in question to see whether u can think more in deep , or several conditions changed,
and they asked to redesign/rewrite answer.
R-4) Face to Face Round 2 :
Q1) Class diagram of one system ( don’t remember question)
Q2) Find Leader in Array ( Leader means an element which is higher than all number which
are indexed higher than element )
Solution Traverse array from behind to find such elements (simple method)
Q3) K sorted Linked Lists are given sort them in one ( write sudeo code )
Then he told me to give logic to solve question without using auxiliary array ( result array
)
I did with in-place method, searching and storing nodes in one linkedlist only.
R-5) Face to Face Round 3 :
Only One question was asked : Rotate Array “D”times.
Different strategies discueed, He was impressed with my another method to find new array
location based upon array size N and D.
R-6) Face to Face Round 4 :
Questions were from different topics like
-OS fundamentals
like fork, child process creation and output if I use fork().
What is deadlock, write sample C code to create deadlock.
What is mutex, etc.
SQL Fundamentals.
Data Structure used in Query,
Sample Query like finding Manger’s name and Fundamentals of join
-Other General Quesions
How Google Search engine works. Where Query goes their server, data storing etc
What happens when you click on website address.
-Design GAME.
GAME is like two players are fighting and ( kind of street fighter ) and design class diagrams
and methods for this GAME, I can think any functionalists(like health, power, help from
friend, etc ) any extra thing apart from which he mentioned.
– API is given, and this API servers different clients,
Now one client has requirement so that functionality changes, but other clients dont need
such functionality, how will you design your system.
– OOPS fundamentals were discussed like
Static, Class can be protected or not, overloading and overriding difference and implemen-
tation of them,
Software patters discussed like Factory and Abstract Factory
Singleton and how to implement it.
394
Chapter 153. Set 152 (Kindle Team SDE-1 )
Last Question was, If I want to store student data such that some students took Physics,
some took Chemistry and some took both. I want to know all details of students, mark,
name etc also. which way I’ll implement this system, which Data Structure will be used,
and which design pattern.
After All this round I was told to go home and Hiring Manager Round will be taken onsite
at Chennai, I was told.
for One month my rounds were not scheduled.
One fine day I got change to give Project Manager round over phone ( they said Senior
Manager will take onsite round and then HR round will be there)
Round 7) Hiring Manager Round.
Over call he asked me first question
Q1) Array is given which is of 0 and 1, all connected 1 forms island.
Find largest size island in given Array,
I have provided working code, He then asked me to optimize and again writing code.
Q2) Design LRU system. I have explained this
and also class diagram and pseudo working code was submitted.
Again for 20 days I didnt got call from HR and when I used to mail him, He simply replied
that my candidature is on hold as Senior Manager is not free to take my next round.
And Today Again I got call that I am rejected. because Hiring Manager is not convinced
from my approach in round,
I still don’t know what went wrong as both code given to HM were working.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-152-kindle-team-sde-1/
395
Chapter 154
Set 152
396
Chapter 154. Set 152
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-152/
397
Chapter 155
398
Chapter 155. Set 153 (For SDE1)
with the help of interviewer i wrote O(n) time solution with O(1) space. Hint: selection sort
Round 4: 1.5 hour – with SDE2
Q1. Given a file having many words. Given K, find the words appearing >=K times. Lots
of discussion was there, discussed many approaches.
Q2. Design data structure that supports insert(), remove(), find-max(), delete-max() opera-
tions. All operations should run in O(1) time. Lots of discussion was there, discussed many
approaches.
Q3. Given two link-list that represents polynomial. Write program to multiply both poly-
nomial , return result as new link-list.
Q4. Write program to find max size BST from given binary tree. Algorithm and full
working code was required for all the problems. Discussed space and time complexity of
every problem.
Still hiring manager round and senior manager rounds are there. Once completed i will post
Tips: Discuss various approaches with interviewer. Try to interact continuously with in-
terviewer. they were very friendly during interview.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-153-sde1/
399
Chapter 156
400
Chapter 156. Set 154 (For SDE2)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-154-sde2/
401
Chapter 157
402
Chapter 157. Set 155 (On-Campus)
This was for about 2 hours. Although there were only two questions but the interviewer is
checking if we have enough knowledge on all the data structures.
1) You are given a long array and window size w. You can only view elements that are
currently in the window. Window starts at the extreme left and moves one position at a
time to the right. You are required to output minimum numbers in the current window.
All the possible approaches were discussed. Starting from brute force, o(nw) to o(nlogw)
using heaps, BSTs. He asked me to implement them. But he was not satisfied with o(nlogw)
solution. He wanted me to give a o(n) solution. Finally after few hints I’ve solved it using
doubly linked lists.
2) You are given a binary tree. Print the vertical order traversal starting from the root
element.
Third Round:
Started off with the question “Explain one project of yours”. Few technical questions were
asked on the project.
Few questions on OS, Multithreading vs Multiprocessing were asked. Also he asked me
to tell if I have implemented any program that used multi threading. Few questions on
semaphores and mutexes were asked.
Only one coding question in this round
1) You are given a very large binary tree, return the root node of the largest BST in the
given tree. Single traversal solution is expected. Implementing it on paper was little difficult
than expected.
Fourth Round:
By this time, job offer was almost confirm.
He asked questions on my projects. He asked me to implement few algorithms from my
project on a paper.
1) Implement a graph and one graph traversal using oops.
2) Given an immutable(non editable) linked list and a number k, remove all occurrences of
the number in the list.
Few questions on OOPs were asked.
They gave me the result after 20 minutes �
I would like to thank geeksforgeeks which helped me enormously in getting placed.
Majority Element
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-155-campus/
403
Chapter 158
10
/ \
5 8
5-10-8 has two turns
10
/ \
404
Chapter 158. Set 156 (On-Campus)
45 56
/ \ \
10 20 45
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-156-campus/
405
Chapter 159
406
Chapter 159. Set 157 (On-Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-157-campus/
407
Chapter 160
408
Chapter 160. Set 158 (Off-Campus)
be dependent on number on dice? You have been given information about ladders (there
are no snakes J ). I used DP.
There were few others that we didn’t discuss as I told him that I know solution to them.
Round 4: 1 hour
Q1. Write an efficient program to count number tree structures that can be made using n
number of nodes.
Basically T(n)=summation (T(i) * T(n-i-1)). I used DP as there are a lot of sub-problems
used again and again. O(n2) .
Q2. There are n nuts and n bolts represented in two different arrays and a function
is_fit(nut_i, bolt_j) which returns 0 if its perfectly fit, 1 if it’s a tight fit and -1 if its
loose fit. I was asked to arrange them so that every nut fits perfectly with the bolt in the
same position (there is one nut for every bolt that fits perfectly). I suggested O(nlogn)
solution.
Q3. Find the kth largest element in a BST. Well that was easy J
We discussed about projects and he asked reasons for leaving present company.
Round 5: 1 hour hiring manager round
Most of the questions were behavioral questions like dealing with manager in case of conflicts,
reasons for leaving present company, why would you choose Amazon and not Flipkart if you
have offers from both, about my projects and contribution to present company.
Round 6: Technical + Behavioral
Q1. How to know the time between someone writes Amazon.com and the page appears
on his browser for a particular user. I impressed him by suggesting to use dummy request
packets after the page is loaded completely sending the time J.
Q2. He showed me the Amazon page they were working at that time and I asked me to
suggest 5 changes in 5 minutes.
Q3. https://www.geeksforgeeks.org/find-a-tour-that-visits-all-stations/
I messed up with the solution in the beginning but reached to solution eventually.
Many behavioral questions were asked too.
TIPS:
1. Don’t jump into solutions, ask about the type of input that is given and output that is
expected.
2. The interviewer always tries to take you to the most optimal solution so listen to what
all he says. Many a times they are big hints !!!
3.Be honest.
4. Keep believing that you will get the job J.
I would like to thank geeksforgeeks team for such an amazing platform to learn and discuss
with other geeks.
All Practice Problems for Amazon !
409
Chapter 160. Set 158 (Off-Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-158-off-campus/
410
Chapter 161
411
Chapter 161. Set 159 (Off-Campus)
Q1. Detailed discussion on projects, best project you have got, the most challenging work,
strengths, weaknesses etc.
Q2. Given a dump of items sold in a file (not organized), give the top n items sold. Eg. the
file looks like:
< item1 sold >
< item2 sold >
< item1 sold >
< item9 sold >
Also, there might be same items sold but they might have different names because of different
vendors. So you also need to count them together (Hint: Use ids of the items).
Hint: Use grep command to get the counts.
Q3. Collect email-ids of all the persons above 18 yrs in a city. He wanted to see my way of
thinking and how do I use software approach towards daily life problems.
Q4. There is a signal and two way traffic. Cars are coming @rate 10 cars/sec. Signal remains
green/red for 10 secs and when the signal is green, 10 cars/min can cross the signal. You
need to tell how many cars are in the line waiting behind the signal on both sides during a
particular time. Say you run the simulator at time 0, now after 1 hour you need to tell the
no. of cars waiting on both the sides.
I didn’t get selected after this but got a call after 1 month as they wanted to reconsider my
profile.
F2F Hyderabad
1st Round:
Q1. Some discussion on previous work.
Q2. Given a sorted array S of characters say S= {‘a’,’d’,’g’}, you need to find the insertion
point of a given character in it such that if it is less than ‘a’, insertion point is 0, if between
‘a’ and ‘d’, insertion point is 1 and if greater than ‘g’, again the insertion point should be 0.
O(log n) time soln was expected.
Q3. Given a complete binary tree, connect nodes at the same level without using any extra
space.
Q4. Given a dictionary of unknown language, you need to give the sorted sequence of
characters in it.
E.g.
Dictionary looks like:
ABCDE
CF
DG
so the output may look like: ABCDEFG
Hint: Topological sort
2nd Round:
Q1. Given two arrays S1 and S2 of characters. You need to find the smallest length of
substring in S1 which contains all the characters of S2. Characters need not be in the same
order as in S2. Characters might be repeating in S1.
Q2. Given a dictionary like text file, find n top occurring words in it i.e. n words whose
count is the maximum. Hint: Use Hashing and Min-Heap.
I would like to thank geeksforgeeks as it helped me a lot while preparing for the interviews.
All Practice Problems for Amazon !
412
Chapter 161. Set 159 (Off-Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-159-off-campus/
413
Chapter 162
Telephonic round :
Design a site similar to junglee.com. Assume you are given a crawler, design a distributed
system , what ds will you use , some basic api’s etc.
Onsite:
coding round 1:
1. zig zag traversal of binary tree O(n) algo
2. matrix question:
given matrix like :
abed
bcfe
abdd
….
find the longest path of consecutive alphabets given a starting alphabet. You can move in
all 8 directions. for eg. a->b(right)->c(down)->d(diagnal down)… len = 4 , find max such
len
coding round 2:
1. is binary tree balanced : O(n) time algo
2. given a pre and post order kindof a traversal (2 arrays) create an n-ary treee out of it
with struct of the form :
struct node {
int data;
struct node *child[MAX];
414
Chapter 162. Set 160 (For SDE 2)
int child_num;
}
did it using a hash table of linked lists and storing parents . Might be a btr way not sure.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-160-sde-2/
415
Chapter 163
Amazon Interview Experience | Set 161 (Off Campus for SDE-1, Bangalore) - GeeksforGeeks
Off campus- Delhi drive (SDE-1 Bangalore)
1st round: f2f
Tell me about yourself.
Most challenging task.
https://www.geeksforgeeks.org/connect-leaves-doubly-linked-list/
https://www.geeksforgeeks.org/check-for-balanced-parentheses-in-an-expression/
Small modification in it. Parenthesis pairs are given in a separate list. You have to optimize
the problem by suggesting the method you will need to store the pairs.
2nd round: Hiring manager
What is the angle between hour and minute hand at 12:15. I said 90’ but corrected myself
immediately.
So he told me the importance that for huge no of clients this small mistake can create a
blunder.
He asked me a scenario where I faced this thing and thereby improved the time complexity.
Lot of behavioural questions like conflicts with manager, team collaboration etc.
3rd round: f2f
https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/
http://stackoverflow.com/questions/20026243/find-2-missing-numbers-in-an-array-of-integers-with-two-missing-va
He asked me if have heard of nut and bolt problem. I didn’t so he moved to next question.
Given an array. Find the maximum number of groups of size of 2 or 3 that can be formed
such that sum of the numbers in group is divisible by 3. No number can be reused.
416
Chapter 163. Set 161 (Off Campus for SDE-1, Bangalore)
Tips: Solve all the data structures related problems from geeksforgeeks and start practicing
to write perfect code for any problem.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-161-off-campus-sde-1-banglore/
417
Chapter 164
Set 162
418
Chapter 164. Set 162
Round 3.
Q-1: https://www.geeksforgeeks.org/maximum-sum-path-across-two-arrays/
Q-2: https://www.geeksforgeeks.org/dice-throw-problem/
Round 4:
Discussion on current project in company and college problem.
Questions on OS.
Q-1: Given 2 files find common words.
Both files are too large to be loaded in memory.
Q-2: Point of inflexion in an infinite mathematical graph which is strictly increasing then
strictly decreasing. Simple binary search was not the solution.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-162/
419
Chapter 165
420
Chapter 165. Set 163 (For SDE II)
is important for amazon. Prepare your project details and think of your real fault, real
problems to tell the manager.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-163-sde-ii/
421
Chapter 166
422
Chapter 166. Set 164 (For SDE I)
Round 2
1. Count the decoding for a given digit string. Let say ‘A’ -> 1, B -> 2 and so on
Eg :
2. There is a printer printing characters continuously on paper, you need to cut the required
message character by character from the printed paper efficiently
Round 3
1. https://www.geeksforgeeks.org/largest-sum-contiguous-subarray/
2. Given a 2D matrix consists of only 0’s and 1’s find the longest diagonal of all 1’s
3. Optimization on above question with slight variations.
423
Chapter 166. Set 164 (For SDE I)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-164-sde/
424
Chapter 167
425
Chapter 167. Set 165 (For SDE I)
Did you ever been in any kind of disagreement with your management?
Work in current company ?
Design snake and ladder game. What data structure would you use, with design was needed.
He then asked to optimize it further.
Given two linked list , find the sum of those linked list . With recursion and without
recursion. Lists may be same or different lengths. Complete code was needed with space
and time complexity.
Fourth round –
General discussion and Introduction. Work about current company?
What is the major challenging task that you have faced till date? Then more discussions
and questions on the task.
Any disagreement with manager and any good or innovative idea that you have come up
with and worked on it?
One technical question – Given a word and the dictionary, find all the anagrams of the
particular word present in dictionary (That are valid words). Propose the data structure
you have used and time complexity of the solution.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-165-sde/
426
Chapter 168
Telephonic 2:-
1. ZigZag traversal of tree
2. Pair wise elements which sum to a given value
3. Intersection point of two linklists
F2F round 1:-
1. Maximum in sliding window
F2F round 2:-
1. You have a list of program files, how will you decide which file to compile first and which
later, what data structure you will use for storing these dependencies.
2. Best Fit
3. You have been given time intervals of a you tube video watched mostly. You have to find
out the most watched time interval, so that you can put an ad in between that section.
F2F round 3:-
1. Find a number in an infinite stream of sorted numbers.
2. What happens when a computer starts?
3. Write a hashing function for storing stream of words.
427
Chapter 168. Set 166 (For SDE I)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-166-sde/
428
Chapter 169
Amazon Interview Experience | Set 167 (SDE I for 1 year 6 months experience) - Geeks-
forGeeks
Round1: Online Coding Round
There were 4 coding question. Was asked to answer 2 out of 4.
1) Given a list of N coins, their values (V1, V2, … , VN), and the total sum S. Find the
minimum number of coins the sum of which is S (we can use as many coins of one type as
we want), or report that it’s not possible to select coins in such a way that they sum up to
S.
Example: Given coins with values 1, 3, and 5.
And the sum S is 11.
Output: 3, 2 coins of 3 and 1 coin of 5.
2) Given two rectangles, find if the given two rectangles overlap or not
3) Given two strings string1 and string2, find the smallest substring in string1 containing
all characters of string2 efficiently.
For Example:
Input string1: “this is a test string”
Input string2: “tist”
Output string: “t stri”
4) I don’t remember the question.
Round 2: F2F Technical (Hyd)
1) Print zig zag of tree
2) Longest Palindromic subsequence of a given string.
Was asked to write complete code.
429
Chapter 169. Set 167 (SDE I for 1 year 6 months experience)
Since my project relates to multiprocessing, lots of questions were asked why multiprocess-
ing/why not multithreading, difference, what is thread/process, producer consumer problem,
etc.
2) Design a file structure in Linux.
3) I was asked to write flawless code for inserting an element in sorted linked list which
should cover all corner cases.
When C requests the server, C should get ID3 as 1st, ID2 as 2nd and ID1 as 3rd meeting.
3) Many behavioural questions.
I would like to thank geeksforgeeks for helping me to crack the interview.
All Practice Problems for Amazon !
430
Chapter 169. Set 167 (SDE I for 1 year 6 months experience)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-167-sde-1-year-6-months-experience/
431
Chapter 170
Set 168
Interview 2
The interviewer asked me about networks in relation to sockets and ports when he saw an
academic project that was mentioned in my resume.
The interview questions were as follows:
1) Given a binary tree where value at each node is a single digit, find the sum of numbers
generated by each root to leaf path. He also asked to code the primary function for the
same. I couldn’t find the exact question on geeksforgeeks, but this one is close enough
https://www.geeksforgeeks.org/find-the-maximum-sum-path-in-a-binary-tree/
2) Given a numpad such that every number is associated with a set of letters, give all
combinations of strings that could be formed given a string of numbers. He also asked to
code the primary function for the same.
Solution: https://www.geeksforgeeks.org/find-possible-words-phone-digits/
Interview 3
1) Given an array of integers, find a subset of numbers from this array such that, after
negating the elements of this set, the total sum of all elements would be equal to zero.
I could not solve the problem and he moved on to the next one after giving me a hint to
use Dynamic Programming
432
Chapter 170. Set 168
2) Given two sorted arrays find the median of the merged array without using extra space.
I gave an O(N) Solution and he asked me to give an O(log(N)) solution,which I gave after
I put in some thought
3) Print a binary tree in a zigzag order level wise. I gave an implementation using a doubly
ended queue, he wasn’t satisfied as this would lead to extra space complexity for storing
the levels in the d-queue. He was pleased when I decided to use 2 queues for the same. He
further asked me to code it up
Interview 4
1) The interviewer asked me about the types of database I knew and elaborated a bit on
non-relational databases like mongodb and JSON.
2) Next, he asked me the need for indexing in databases and it’s implementation.
3) In an auctioning system, the bidder with the highest bid wins but charged at kth highest
price. Develop a system for it. Solved it using a hashmap. Was asked to write a code for
the same.
4) Given an array such that all elements except one are duplicate, find this element. He
tweaked the problem to add the condition that in stead of one there are 2 such elements. I
couldn’t arrive to a solution even after he gave me some hints. In the end he gave me the
answer but immediately said that it may not work. I realized why it did work and explained
the reason for the same.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-168/
433
Chapter 171
434
Chapter 171. Set 169 (For SDE 2)
6.ODG
Re-arrange it such that every line has the index of all of its anagrams
Eg Output
1.CAT 1,3,4
2.DOG 2,5,6
3.TAC 1,3,4
4.ACT 1,3,4
5.GOD 2,5,6
6.ODG 2,5,6
2. Given inorder and postorder traversal of a tree give the preorder traversal without creating
the tree.
Round 5 Hiring Manager Round
1.Nut and Bolts Problem
2.Given a million list of co-ordinates in the form of longitude and latitude just as Google
maps .How will you print closest k cities to a given location .
After that a few behavioural questions
I was not able to come up with a good answer for second question.
I thank geeksforgeeks for creating this amazing platform.Great job guys.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-169-sde-2/
435
Chapter 172
Set 170
436
Chapter 172. Set 170
Ex – 3 chapter with 10 pages each and user has to complete this book in 2 days, then the
schedule should be either be 2 chapters on first day and 1 chapter on second or 1 chapter
on first day and 2 chapters on second. (code)
2. Tell me about a time when you couldn’t implement the best solution because of a close
deadline.
3. What did you do about it afterwards.
4. General design pattern related questions like what if we use singleton design pattern for
question 1
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-170/
437
Chapter 173
Set 171
438
Chapter 173. Set 171
CàE
DàF
Input Tokens :
1. A,C then all A,B,C,D,E,F are possible.
2. A then A,B,D,F are possible.
Ask me what data structure you will use, how processing will happen. Pseudo code was
required.
Round -4 (F2F)
Long discussion on my current work. Biggest challenge and how you solve it. Technology
challenge.
Q-1: Suppose you receive 10 million mails in 10 seconds. How will you process them and
find whatis problem to receive these many mails. Discussed different approaches.
Q-2: longest palindromic substring of given string. I gave DP solution, he ask me don’t use
DP. Proper code was required.
https://www.geeksforgeeks.org/longest-palindrome-substring-set-1/
Round-5 ( Telephonic)
Long discussion on my current work again, Challenges faced. What you did when some
mess-up happens and deadline is very strict. Conflict with manager.
Q-1 : Outlook:
A server receives meeting objects from multiple senders. Meeting object contains meeting
time, sent time, recipient(s), sender id,etc. When recipient comes and checks the server,
he/she should get requests based on meeting time and not based on sent time. Many
discussions on space complexity and time complexity.
Eg:
When C requests the server, C should get ID3 as 1st, ID2 as 2nd and ID1 as 3rd meeting.
Q-2 : https://www.geeksforgeeks.org/add-greater-values-every-node-given-bst/
I gave solution using temp array, then he ask me to do in constant space in single traversal.
Condition don’t use pointer for sum or call me reference. Proper code was required.
Tips: Be yourself . Practice writing code on paper. Never give up.
Thanks Geeksforgeeks for providing very good platform to well prepare. A knowledge
repository J
439
Chapter 173. Set 171
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-171/
440
Chapter 174
441
Chapter 174. Set 173 (On-Campus)
arr[] = {1, 2, 3, 1, 4, 5, 2, 3, 6}
k=3
Output :
3345556
Q2: Given Two sorted array of size size n each. Find the Kth largest element in these two
array (Expected Time Complexity Log(n))
Round 4(F2F)
Detail Discussion about project
Q1.website having several web-pages. And also there are lot many user who are accessing
the web-site.
say user 1 has access pattern : x->y->z->a->b->c->d->e->f
user 2 has access pattern : z->a->b->c->d
user 3 has access pattern : y->z->a->b->c->d
user 4 has access pattern : a->b->c->d
and list goes on for lot many users which are finite and numbered.
Now the question is we have to determine the top 3 most occurring k-Page-sequence.
for the above example result will be : (k=3) a->b->c , b->c->d , z->a->b.
Q2: Given two array , one of size m+n and contains m element and other position are empty
, 2nd array is of size n and contains n element.
both array are sorted , now merge the second array to first one such that the resultant array
is sorted. Expexte time complexity(m+n).
I would like to thanks geeksforgeeks for providing such a platform to learn algorithm and
data structures… � �
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-173-campus/
442
Chapter 175
Element NGE
4 --> 5
443
Chapter 175. Set 174 (For SDE)
5 --> 25
2 --> 25
25 --> -1
d) For the input array [13, 7, 6, 12}, the next greater elements for each element are as
follows.
Element NGE
13 --> -1
7 --> 12
6 --> 12
12 --> -1
444
Chapter 175. Set 174 (For SDE)
2 3 1
/ \ / \
1 3 1 3
\ /
2 2
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-174-sde/
445
Chapter 176
446
Chapter 176. Set 175 (For SDE)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-175-sde/
447
Chapter 177
448
Chapter 177. Set 176 (For SDE 1)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-176-sde-1/
449
Chapter 178
Amazon Interview Experience | Set 177 (First Round in Pool Campus) - GeeksforGeeks
Today Amazon Took a Pool campus drive, including our college and many other. In which
the First round was Online in our campus itself, those selected students would go for further
rounds in other campus.
The First Round Was very Standard, first we had to open its Hiring test portal, in which it
had 20 MCQ and 2 coding questions, which we had to complete in 1:30 Hrs.
MCQ:
Coding:
1: given 3 Numbers in Linked list, we had to return the Linked List of representing sum of
all three, covering all base and condition of addition.
450
Chapter 178. Set 177 (First Round in Pool Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-177-first-round-pool-campus/
451
Chapter 179
10
/ \
6 17
/ / \
4 14 19
So the Linklist will be
10->null
6->17->null
4->14->19->null
Gave the answer using the 2 queue. (Level order transversal) with alternate queue for the
alternate level
Than interviewer asked to solve the problem without using any other data structure (No
stack or queue)
452
Chapter 179. Set 178 (For SDE-1)
Ex:
INPUT:
String: "abfugtabecddcca"
Character Set: a,b,c
Output: 4 ("abec")
Ex:
a b c d
l m n e
k p o f
j i h g
output: a b c d e f g h i j k l m n o p
453
Chapter 179. Set 178 (For SDE-1)
Thank you geeksforgeeks for providing the awesome platform for preparation.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-178-sde-1/
454
Chapter 180
455
Chapter 180. Set 179 (For SDE-1)
1) Given a 2-D array, in which all the elements are either 0’s or 1’s, and all the rows are
sorted, Give an algorithm for finding the row having the maximum number of 1’s. Was
asked to code and analyse time complexity as well.
2) There is a given set of colours , say [1-N]. Now , people are coming into a stadium wearing
t-shirts of any of these colors. Write an algorithm to find the first person to come in, to
have worn an unique color.
The question wasn’t clear to me at first, so after a few examples , got what he was trying
to ask.
For eg. Suppose we have colors R G B
and the stream of people are as,
GRBGGGG
the output should be R.
Hope this helps some people.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-179-for-sde-1/
456
Chapter 181
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-180-telephonic-interview/
457
Chapter 182
458
Chapter 182. Set 181 (For SDE 1)
related stuff.
2. Simple Matrix multiplication problem ,with only 2 double pointer are given , we need to
check sizes of both matrix , multiplication feasibility and then do multiplication .
3. Design Question from DataBase point of view , asked about table structure for the
problem and had a good discussion on it , concept such as normalisation was discussed .
Telephonic 4th
He was a very senior guy from different team ,
1. Started with general introduction followed by many Behavioural hr questions .
2. Followed by Design Question, a feature of Outlook
A Server receives meeting objects from multiple senders. Meeting object contains meeting
time, sent time, recipient(s), sender id,etc. When recipient comes and checks the server,
he/she should get requests based on meeting time and not based on sent time. Many
discussions on space complexity and time complexity.?Eg:
12 PM From: A To: B,C,D meeting time: 4 PM meeting Id: 1
12.30 PM from: A To C,D meeting time : 2 PM meeting Id:2
1:PM From B To: C meeting time: 1.30PM meeting Id:3
When C requests the server, C should get ID3 as 1st, ID2 as 2nd and ID1 as 3rd meeting.
Small set of Suggestions :
1. Practice writing code using pen and paper .
2. Try to be interactive as they are very much interested in candidate’s thought process ,
think loud , be confident .
3. Firstly explain the logic and when interviewer is satisfied then start coding .
4. Have few questions prepared for the interviewer as it shows interest of candidate towards
the company .Do proper home work about the company.
Thanks GeeksforGeeks for such a great content , Keep doing the great work �
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-181-for-sde-1/
459
Chapter 183
460
Chapter 183. Set 182 (For SDET 1)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-182-for-sdet-1/
461
Chapter 184
Amazon Interview Experience | Set 183 (SDE - New Grad Position) - GeeksforGeeks
Following is my experience. I hope it helps people out there, as I got help from other posts
here before my interview.
Duration: 4 hours
interviewer #1: 8 am – 9 am
Q1) tell me your interest
-> Big Data
Q2) what’s latest thing you follow in it
-> Apache Spark
Q3) What is it and explain
-> told the standard MapRed and Hadoop vs Spark
Q4) what more features
-> told graph processing and MLLIB
Q5) Actual question starts here, given the binary tree, how will you serialize and deserialize
it to the file?
->
answer1: Serialize => do in-order traversal and pre-order traversal and write it to a file
Deserialize => build the binary tree using pre-order and in-order traversal
he was not satisfied, gave me hint of no need to do complex in-order, pre-order thing
answer2: BFS clicked me, told him to do BFS and write to a file level wise
But he found a bug in deserialize method, I changed the serialize method for null
values to speial character in file
he was okay with it, and asked me to write a code for it
asked the complexity
told him, was not convinced wholly, then finally told him, was still not
left the room with think over it �
462
Chapter 184. Set 183 (SDE – New Grad Position)
463
Chapter 184. Set 183 (SDE – New Grad Position)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-183-sde-new-grad-position/
464
Chapter 185
Amazon Interview Experience | Set 184 (Off Campus for SDE1) - GeeksforGeeks
I interviewed with Amazon, Hyderabad. Interview was in October, 2014. I was 4 months
experienced, and was applying for SDE-1 position.
I had 4 interviews, and my experiences are as follows.
1st Round
Q1 – Clone a graph. ( Similar Question -> https://www.geeksforgeeks.org/clone-linked-list-next-arbit-pointer-set-2/)
Basically while cloning, when you create a new node in the cloned graph, have a hashmap
which maps the old node to new node.
So in the hashmap key = old node, value = new node.
Q2 – Given an array of numbers, for each number print the first number to it’s left which
is greater than the current number.
Example
Input -> 5,3,2,4,8,6
Output-> -1, 5,3,5,-1,8
Use stacks. Simple O(n) solution.
2nd Round
Q1 – Find the row number according to the excel nomenclature –> (the opposite of this,
https://www.geeksforgeeks.org/find-excel-column-name-given-number/)
465
Chapter 185. Set 184 (Off Campus for SDE1)
There were a lot of edge cases, and discussion with regards to this. ( I took a lot of time
and the manager did not seem to pleased. � )
Q2- In a sorted array, find two numbers who’s difference is k.
https://www.geeksforgeeks.org/find-a-pair-with-the-given-difference/
A lot of questions as to Why Amazon, Why do you want to leave so early.
4th Round(Bar Raiser)
Q1 – Given a sorted array find a number. (Simple Binary Search)
Now consider repetitions and find the left most occurrence. (Binary Search to first find
number, then again Binary Search to find left most occurrence)
Similarly find the right most occurrence. (Binary Search to first find number, then again
Binary Search to find right most occurrence)
Now using the above two functions, find the number of times the element is present.
Note – Cases like where number is NOT present,
Q2- Assembly Line Scheduling. (Very Simple DP.)
https://www.geeksforgeeks.org/dynamic-programming-set-34-assembly-line-scheduling/
Result
After three weeks, I got a generic email saying that I could not clear it. I had a really
irresponsible recruiter who did not have the courtesy to give me a call and just convey some
feedback. Eventually, I think I took too much time with the first question in the manager
round.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-184-off-campus-for-sde1/
466
Chapter 186
467
Chapter 186. Set 185 (For SDE1)
2. Given an input string and a dictionary of words, find out if the input string can be
segmented into a space-separated sequence of dictionary words.
Solution https://www.geeksforgeeks.org/dynamic-programming-set-32-word-break-problem/
F2F Round 4:
Discussion of projects and current work experience.
Diameter of a binary tree in o(n).
First devised o(n^2) then optimized to o(n)
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-185-for-sde1/
468
Chapter 187
Round 2(F2F):
1. Find if the given binary tree is height balanced.
Round 3(F2F):
1. Find if the given tree is the subtree of the big tree.
2. Given a sorted matrix (row-wise and column wise) , find kth smallest element.
3. Given an array. Pop min element in O(1) time.
4. Implement increment operator for the array.
Round 4(F2F):
1. Print the level-order traversal from bottom to up in a given binary tree.
2. What is process and thread?
3. What is copy constructor?
4. Design parking lot.
469
Chapter 187. Set 186 (For SDE1)
2. Given a file with millions of URLs. Some URLs repeating , some unique. Find the first
unique URL.
Coding was required in each and every round. Think loud. Tell the interviewers what you
think. Give them different approaches. Be confident about your solution.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-186-for-sde1/
470
Chapter 188
471
Chapter 188. Set 187 (For SDE1)
472
Chapter 188. Set 187 (For SDE1)
473
Chapter 188. Set 187 (For SDE1)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-187-for-sde1/
474
Chapter 189
475
Chapter 189. Set 188 (For SDE1)
3. Asked me which is the best project I have done and asked me how do I improve its
functionality, discussion went on this.
Tips:
They will help you are struck just think loud.
Practice writing code on paper.
I thank GeeksForGeeks for this great work. �
All Practice Problems for Amazon !
Group Anagrams Together
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-188-for-sde1/
476
Chapter 190
Telephonic Round 2 :
—————————
I must say this guy who interviewed me was really smart. This round was a little more than
1 hour and there were 3 questions.
1) BST to Singly Linked List in place. A slight modification of this problem — https:
//www.geeksforgeeks.org/convert-given-binary-tree-doubly-linked-list-set-3/. Coded it.
477
Chapter 190. Set 189 (For SDE-1)
F2F R1:
————–
Started with introduction. A lot of questions about current company, current work, current
project and then a design question.
How would you design the meeting invite feature of Microsoft Outlook? Considering each
meeting invite as an object and that Web server is the storage space for the invites, design
a data structure to receive and send invites to user in an efficient manner. The message
objects must be received in a sorted manner based on the time of meeting. I suggested using
a Binary Search Tree and justified the use of this DS. I gave an O(NlogN) solution. I was
then asked to code it. I coded it in C#.
Followed with a lot of HR questions.
478
Chapter 190. Set 189 (For SDE-1)
F2F R2:
————–
1) Reverse a sub array in an array. Pretty easy.
2) Rotate a subarray in an array where start and end indices of the sub array are provided
and ‘k’ is provided which is the number of rotations to be done. The interviewer behaved
really dumb in this question. All he wanted was a solution. He made me dry run the code
again and again and he wasn’t really bothered about the concept or the approach. I don’t
think he could relate to my solution which was O(n) in time and O(1) in space.
3) Find if a linked list has a loop. Old question. Take a fast and a slow pointer. But to get
this solution wasn’t really his motive. He asked why slow pointer should move by one node
at a time and why the fast pointer should move at the speed of two nodes at a time. As led
by the discussion, I was then asked to find the optimal speeds of slow and fast pointers for
a given linked list. Again, led by the discussion, he asked if it’s given that the linked list
has a loop and the size of the loop is given, can I find the optimal speeds of the slow and
fast pointers?
F2F R3:
————–
1) Same question as Q3 asked in telephonic round with the only difference that the heights
of the buildings was provided in a linked list. Coded it in C. Then, the interviewer twisted
the question by placing the sun after the last building(previously the sun was placed before
the first building). Used a stack. However, this can simply be done by the reversing the
heights array and using the same function written for the first part of the problem.
2) Design a data structure to represent the hierarchy of employees in an organization. Also,
the design should be such that, you can retrieve the no. of reportees of a manager(not just
the direct reportees but all the employees under him) very fast(O(1) was expected). Also,
insertion of a new employee and removal of an employee should be fast too.
I suggested using a n-ary tree of hash tables. Also, used an additional hash table where key
was employeeId and value was the address of the hash table (or the node) in the n-ary tree.
My solution did give no. of reportees in O(1) and addition and removal of employees was
in O(n) time, where n is the total number of employees. There wasn’t enough time to code
though.
F2F R4:
————–
This round had a lot of HR questions. Cultural info. Current project. He also asked coding
questions but he wasn’t really bothered about the optimality of the solution.
1) Two nodes in a BST are swapped. Find them. Told my approach. Didn’t ask me to code
it.
2) Print all the permutations of a string in lexicographic order. Coded it. Took me a lot of
dry runs to make him understand that the code is correct �
All Practice Problems for Amazon !
479
Chapter 190. Set 189 (For SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-189-for-sde1/
480
Chapter 191
481
Chapter 191. Set 190 (Delhi Drive)
4) Implement garbage collector. (Had no idea how to do that, but took some time and was
able to tell an approach to maintain reference count in hashtable. He asked to code the
approach)
Three rounds were completed on a day and fourth and final round was telephonic. My last
round turned out to be negative because I was not able to write complete code in given
time.
Still the problem asked in round 1 and round 2 were new to me and was able to solve those
using different approaches which I have learned from Geeks for Geeks. �
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-190-delhi-drive/
482
Chapter 192
Set 191
hash(key)
{
return key%1000;
}
and your own hash operations. Did it using hashmap with pointer to an avl tree.
483
Chapter 192. Set 191
Source
https://www.geeksforgeeks.org/amazon-interview-experience-191/
484
Chapter 193
Set 192
485
Chapter 193. Set 192
Result- HR said that you will offered a job. But a week later I got rejected. I found their
process highly arbitrary.
Practice code on paper and get to know on what criteria you are getting selected.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-192/
486
Chapter 194
https://www.geeksforgeeks.org/backtracking-set-3-n-queen-problem/
I had a long discussion on this question finally he was satisfied with my solution.
2. Write a program to find the sum of maximum sum subsequence of the given array such
that the intgers in the subsequence are sorted in increasing order.
https://www.geeksforgeeks.org/dynamic-programming-set-14-maximum-sum-increasing-subsequence/
3. Given a Binary Tree, check if all leaves are at same level or not.
https://www.geeksforgeeks.org/check-leaves-level/
3rd round –
Given a sorted array arr[] and a number x, write a function that counts the occurrences of
x in arr[]. Expected time complexity is O(Logn)
487
Chapter 194. Set 193 (For SDE-1)
https://www.geeksforgeeks.org/count-number-of-occurrences-in-a-sorted-array/
Find k largest elements in an array. Elements in array can be in any order.
4th round(Hiring manager)-
1. Questions around current job, challenges faced. Any instance of conflict and how you
resolved it.
2. A lot of discussion on projects and work experience.
3. A large file is given you have to find all the anagrams. Told him to divide the file in
chunks for parallel processing and then check anagrams using heap.
5th round(Bar Raiser)-
1. Why you are leaving your current company so early?
2. An integer is given to you,first convert it into binary then reverse this binary string and
print decimal corresponding to this reversed string.
3. He asked one question related to REALLOC function.
In every round, after each question, complexity of the algorithm was asked. Its good to ask
questions to get more clarification about the question.
I want to thank the entire team of geeksforgeeks. It is a great portal and it helped me a lot
in preparing for Amazon interview.
Tips: Discuss various approaches with interviewer. Try to interact continuously with in-
terviewer. they were very friendly during interview.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-193-for-sde-1/
488
Chapter 195
489
Chapter 195. Set 194 (For Software Support Engineer)
one by one to Stack2. Then Pop top element from Stack2 as Result. For Next DeQueue do
reverse, i.e. from Stack2 to Stack1.
2) 1st Technical Round
i) Write Program to Reverse a Linked List.
ii) Discussion on a Scenario and Debugging/Troubleshooting the error.
3) 2nd Technical Round
i) The similar Debugging/Troubleshooting scenario.
ii) Add the Numbers present in the String and display.
E.g. “abc123def-567ghi89jk”
Here take ‘-‘ as negative number symbol.
iii) Find the Pair of Array elements summing up to value ‘k’, in a Sorted Array. Optimize
it from Complexity ‘N^2’ to ‘NlogN’ using Binary Search.
4) 3rd Technical + Managerial Round
i) Some OS Related Questions.
ii) UNIX Commands – Which I couldn’t recall!
iii) Project Experience and Why want to Join Amazon and similar ones.
Though I couldn’t clear the 3rd Round, the overall experience was good.
## Remember:-
—————————
>> Please check their Technical Requirement, and revise your concepts of OS(How Process
works, Process Life Cycle, RAM, Virtual Memory, DeadLocks etc.), UNIX(Revise Basic
Commands like ‘grep’ etc.).
>> Practice basic Problems like, Searching, Sorting, Fibonacci, Factorial, Recursion, Stack,
Queue, Linked List and their Application.
Hope it helps for the new Applicants!
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-194-for-software-support-engineer/
490
Chapter 196
491
Chapter 196. Set 195 (On-Campus For SDE-1)
Only Hardwork and practice helps. And of course your luck on interview day �
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-195-on-campus-for-sde-1/
492
Chapter 197
Source
https://www.geeksforgeeks.org/amazon-interview-experience-196-on-campus/
493
Chapter 198
494
Chapter 198. Set 197 (On-Campus for Internship)
495
Chapter 198. Set 197 (On-Campus for Internship)
496
Chapter 198. Set 197 (On-Campus for Internship)
I had already seen the problem with 2 instead of 100, and when I told him the answer
immediately, it was evident, and so we moved on to the next question.
2) Given a chess board, and a starting position, and a set number of moves, find the
probability that the knight will remain on the board after the moves are done.
Handle all the corner cases, like when if during the first move, the knight goes outside the
board, that traversal ends there.
I had to code the entire thing, on the collaborator, and by habit I kept pressing ctrl+s, and
hence, it kept disconnecting. *facepalm*
He was in a real hurry, but he still made sure he answered all the questions I had for him.
But he was not too satisfied my solution, and gave me time to improve and said he’d come
back in 5 mins, but he didn’t �
General tips:
1) Prepare well, and concentrate on DBMS and OS as well.
2) Be confident, and be interactive.
3) Ask a lot of questions when you are asked to. This is a good time to show them you are
interested in the company, and that you think beyond the coding aspects of the company.
Some of my questions were:
a) What makes Amazon any more customer centric than the other similar e-commerce
websites?
b) How do programmers contribute to how the customer actually feels about the company?
because coders do after all only implement what their managers tell them.
c) Given that this is such a tough interview, how many of such tough questions do you
actually see in production?
4) Having a good resume’ can help you guide your interviews.
Try to be original with your questions
And, all the best �
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-197-on-campus-for-internship/
497
Chapter 199
498
Chapter 199. Set 198 (For SDE1)
How can you merge the strings, by making the cost as low as possible?
Write code of deleteMin, insert, percolateDown operations in Heap.
Solution:
Initially sort the strings in ascending order wrt their lengths. Now take out the first two
strings and concatenate them.
Keep the resultant string in the sorted strings, wrt its length.
Priority Queue will be used to achieve the desired solution here.
2. Given a matrix of size m x n. Here m and n are very large, assume like 1 lakh.
You are given a series of submatrix inside this matrix. Find the sum of all elements inside
each submatrix.
Submatrix positions are given interms of its: top_left_cell and bottom_right_cell.
For eg:
input array: 5 x 6
1, 2, 3, 4, 5, 6
7, 8, 9, 10, 11, 12
13, 14, 15, 16, 17, 18
19, 20, 21, 22, 23, 24
25, 26, 27, 28, 29, 30
submatrix positions:
(3, 4), (4, 5)
which is
16, 17
22, 23
o/p is: 78
Solution: Since there will be multiple submatrix will be given for your, its not optimum
to go element by element for each submatrix. Do some pre-processing, like build another
matrix same size as input matrix, which will contain sum of its sub matrix. This way we
can calculate the sum in O(1) time.
For the above example, the sum matrix is:
1×1 1×2 1×3 1×4 1×5 1×6
2×1 2×2 2×3 2×4 2×5 2×6
3×1 3×2 3×3 3×4 3×5 3×6
4×1 4×2 4×3 4×4 4×5 4×6
5×1 5×2 5×3 5×4 5×5 5×6
Now to find the sum of submatrix: (3, 4) and (4, 5)
sum = sum[maxRow, maxCol) – sum(minRow-1, maxCol) – sum(maxRow, minCol-1) +
sum(minRow-1, minCol-1)
3rd Round:
1. Design a newspaper subscribing system for a user.
What are all the systems to be considered as part of this design?
2. There is a stream of integers coming. At any particular point of time, you are required
to give the first non-repeated element from it.
499
Chapter 199. Set 198 (For SDE1)
For eg: 2, 3, 1, 2, 1, 3, 5
o/p: If I ask you at 2nd position(after 3), the answer is: 2
If I ask you at 5th position(after 1), the answer is: 3
If I ask you at 6th position(after 3), the answer is: “No such element”
If I ask you at 7th position(after 5), the answer is: 5
Solution:
Manager Round:
1. Google crawler question.
Given a set of N documents.
Given k strings: {str_1, str_2, …, str_k)
Now return the document numbers, which contains all the k strings.
2. Given an N-ary tree. Mirror the tree.
Give a suitable tree Node structure for this and write code for the same to mirror it.
eg:
i/p:
1
/ / | \ \
2 3 4 5 6
/ / |
7 8 9
o/p:
1
/ / | \ \
500
Chapter 199. Set 198 (For SDE1)
6 5 4 3 2
/ | \
9 8 7
I haven’t done well in last two rounds. So I got rejected. But it was a nice experience
altogether.
Thanks to geeksforgeeks for hell lot of questions. It takes at least a life time to prepare all
the questions present in geeks for geeks, if we go by one question per day. Thanks.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-198-for-sde1/
501
Chapter 200
502
Chapter 200. Set 198 (On-Campus for Internship)
We have to find the sum of elements in this sub-matrix in O(1) time complexity for each
query.
Eg:
1234
5678
9102
3415
(0,0)-(1,2) : 24
(1,1)-(2,2) : 14
Q2) We are given an alien language, in which we dont know the arrangement of the letters.
Now we are given some words of that alien language in dictionary order.
using those words we need to find the order the the letters of the alien language.
https://www.geeksforgeeks.org/given-sorted-dictionary-find-precedence-characters/
Q3) We are given the preoder traversal of a BST, we need to create the BST using the
given traversal.
But we can’t use inorder traversal(i.e. sort the elements and use the array.)
and also we need to create the BST in single traversal of the preorder list.
Q4) We need to reverse a Linked List using single pointer. (in other words : recurrsively)
He asked me to write the code for reversal.
After this round some students were selected for second round of the interview process.
Luckily i was among them.
F2F 2:(1 hour) (Technical):
This round also consisted of coding questions:
Q1) Given a tree, print the tree in Zig-Zag manner.
https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/
Q2) Given a sorted array, we need to find that element whose value is equal to that of its
index value.
He asked me to do it in log(N) time complexity.
Q3) Given a tree, now the given tree is special as in this tree all node has only 1 pointer
which points to its parent.
Now, in this tree we are given any 2 nodes, and we need to find their lowest common
ancestor(LCA).
Hint: This question is similar to intersection of 2 linked lists.
In the end he asked me if i had any questions to ask.
Thanks to geeksforgeeks �
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-198-on-campus-for-internship/
503
Chapter 201
2. Given a binary tree, find the longest path in the tree. If there are two longest paths print
the lexicographically first path.
EXAMPLE:
504
Chapter 201. Set 199 (On-Campus for Internship)
OUTPUT: D E B A F G
ROUND 2: (DS CODING ROUND)
1. Given a BST and 2 nodes in the BST, find the length of the path between the two given
nodes.
Example:
Input: the below tree and node 3 & 7
Output: 5
505
Chapter 201. Set 199 (On-Campus for Internship)
ROUND 3: (F2F)
1. Given an array where the elements are in absolute difference 1, write an algorithm to
search for an element in the array and return the position of the element. (return the first
occurrence).
Example:
Input: 8 7 6 7 6 5 4 3 2 3 4 3 search element: 3
Output: 7
Example:
Input: madam Output: true
3. It was a scenario question based on facebook. I have to find all the mutual friends of my
friends and my friends of friends of friends. This list returned should be in a sorted order.
To perform the above action u are given a getfriend() function which will return the list of
friends for that id.
Hint: use hashing
ROUND 4: (F2F)
1. It is a graph question. A 2D graph with x and y coordinates. Given millions of points in
506
Chapter 201. Set 199 (On-Campus for Internship)
Input:
given node – F
K=2
Output: A E J K L
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-199-on-campus-for-internship/
507
Chapter 202
Set 200
Interview:
Round 1:
• Given a no, find next no greater than n and having same digits.I was supposed to
write a working code for this on paper.
• There is a robot that is initially at origin. A robot have three operations, he can either
turn left or turn right, or he can move one unit ahead in the direction he is facing.
Given a string containing L (turn left), R (turn right), G (move one unit ahead).Find
if the robot again reaches the point he has been before (find a loop).
508
Chapter 202. Set 200
Example: LGRGRGG
Initial co-ordinate is (0, 0), it turns left and moves one unit, updated coordinates
(-1,0).
Then turns right and moves one unit, updated coordinates (-1, 1).Then turns right
and moves two unit (two ‘G’s). Updated coordinates are (1, 1).
Round 2:
• Given an 2-D array, implement an hash map which when given (key, value), insert and
retrieve value in O(1). Also implement one more functionality that gives me all the
keys for corresponding value in O(n).
• Given a graph whose vertex can have only two value, either 0 or 1. Find no of distinct
clustered ones (island) in the graph. Write a working code for this on paper.
Round 3:
509
Chapter 202. Set 200
Output: 1 2 3 4 5 8
• Given a table that has amount has its column and an integer n, write a query that
give nth largest amount value in the table.
• What are the differences between child processes and threads? Explain virtual memory,
paging concept, page replacement algorithms. Design a data structure for working set
algorithm.
Round 4:
Important tips:
Have a loud thinking, the interviewer helps you if you get struck.
Don’t do silly mistakes while writing code, take your time but have a neat, optimized code.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-200/
510
Chapter 203
• Given 2 strings, check if any one of them has any anagram of the other string, as a
substring of it.
• Graph question : ( not mentioned directly as graph, but was implied). basically
Needed to find the shortest path between two given vertices in the graph.
Interview:
Round 1:
Round 2:
• Given an array of Integers, find the Maximum length subarray with sum equal to
zero. Solved by constructing Prefix sum array for the given array. In prefix sum
array, any number repeating more than once, implies subarray between those indices
511
Chapter 203. Set 201 (On-Campus for SDE-1)
is 0, so store length of this subarray, check for other repeated values too. ( careful
coding required to eliminate bugs) Additionally had used a HashMap(java) to do this
solution time efficiently. {code it}
• Return largest BST from a BT ( geeks question) {code it}
Round 3:
• Tell me About your Internship project. ( It dealt with Performance bench-marking for
embedded Systems ( SoC) with respect to latency and bandwidth done at Samsung
R&D B’lore).
• Given a 2-D matrix of zeroes and ones, any row/column containing a single 1 is made
completely 1. ( available on geeks) I told him I know the space and time optimized so-
lution to it ( as provided by geeks). Asked me to code it… had some bugs, took some
time to debug a particular corner case.{code it}
• He Modified above question, providing conditions -> if there are no limitations on
the space used, and if accessing each cell has a cost attached to it, how would you do
the same problem in least cost.
• Given a tree with three pointers in every node, left, right and next, connect all the
nodes at the same level in a spiral fashion. eg root’s next points to right child which
in turn points to roots left child which in turn points to level 2’s 1st left child … and
so on… any node could have 0,1 or 2 children.( geeks)
Round 4:
• Given the function : int func( int n) { if(n==1) return 1; return n* func(n-1)*func(n-2)
+ func(n-1)*func(n-2) + func(n-1); } // What is its space complexity.
• Given a in-coming stream of numbers ( either 0, 1 or 2), Design a Finite state
machine which tells me if the number formed by the input stream so far, is divisible
by 3. eg stream state is “012” return true, coz 12 is divisible by 3.. for “0111” return
false… { Design the FSM }
• Proposition logic question with 5 statements given, determine their truth. ( Solved
using common sense, but wanted me to prove it mathematically )
• Given an int represented in Big Endian form, convert into into Little Endian, where
the number of bytes taken up by int is not provided. Ex: if int is of 4 bytes and input
integer n= A B C D , => o/p = D C B A => n2 … where the alphabets represent a
byte. return n2. Involved Bit manipulation. { Code it}
• The one thing you regret from the past 3 years in college.
Round 5:
• Introduce yourself.
• Given an n-ary tree, traverse it in level order, printing a particular element in each
level( that particular number is returned by function “func1(int level)”. Gave an O(N)
time and O(N) space complex solution, followed by an O(N) time and O(1) space
complex solution. {code it}
• Advantages/Disadvantages of a static variable inside a class in java.
512
Chapter 203. Set 201 (On-Campus for SDE-1)
• Have a loud thinking, the interviewer helps you if you get struck. Ask ALOT of
questions. At least he will know what you are thinking or where you are going wrong
at.
• Write neat code,”take your time …..as much as you like”.
• Make sure the interviewer has approved the algorithm before you start coding. Discuss
full algorithm before you code. He may ask you to think in a more optimized manner.
• Study “geeksforgeeks.org” well, especially the tree sections, and dont mug up the code,
its no use, you will not remember when needed, instead, understand why every minute
detail of the code. This will take u further.
• Study basics of every computer related subject taught in class. No need to be experts,
but having an idea helps.
• Mostly it is about data structures and algorithms. Make sure you are comfortable
with them.
• Side note: Help others and just do good. Neither hard work nor luck pays. Its all
about your destiny. Dont get worked up about these things. Life has more purpose.
• “Karmaane vadhi karaste ma faleshu kadhachanam..” – Gita
above line means “Keep doing good deeds, dont expect rewards..”
“Nasrum Minallaahi Wa Fathun Qareeb” – The Holy Qura’an
Above line means, “When comes the help of Allah, Victory is near”
Best of luck �
Thank You geeksforgeeks teams.. Thanx a ton �
And thanx to my parents, and friends who helped me alot.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-201-on-campus-for-sde-1/
513
Chapter 204
Set 202
514
Chapter 204. Set 202
F2F Interview
5 rounds in total.
Each round was for 45 mins.
1st F2F
Tell me about yourself
Given three sorted arrays, how will you sort all the three arrays into one array, shortest
time expected
2nd F2F
Design architecture that should handle millions of hits at given time, the response time of
the system should be the least. – ( Hash Map for data storage is something i came up with
and that was accepted. Couldnt come up with a solution for the entire problem.)
3rd F2F:
About project experience and how i handled it. Amazon leadership skills were mostly
expected.
4th F2F:
Sum all the values of the nodes of a Binary tree that fall on the same column and print
them.
The solution is to treat root as the center and any node that moves away from it (left/ right
)one at a step is treated as under same column
5th F2F:
Print the values of a binary tree that occurs on the same level.
-Level order traversing.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-202/
515
Chapter 205
• Given 2 strings, check if any one of them has any anagram of the other string, as a
substring of it.
• Graph question : ( not mentioned directly as graph, but was implied). basically
Needed to find the shortest path between two given vertices in the graph.
• On a number line from negative infinite to positive infinite, if you start from 0, you
can either jump back or front. but every jump length is 1 more than the previous
jump. Given a number on the number line, can we reach it using any combination of
jumps. If yes, print the minimum length path.
• https://www.geeksforgeeks.org/a-boolean-matrix-question/
• https://www.geeksforgeeks.org/find-the-row-with-maximum-number-1s/
Round 2:
• You have n slabs with two dimensions. Stack them to get max height. No rotation
of dimensions required. First he started with 2 dimensions, then 3, 4 and then for n
dimensions.
516
Chapter 205. Set 203 (On-Campus for SDE-1)
• Given a binary tree, a target node in the binary tree, and an integer value k, delete
all the nodes that are at distance k from the given target node. No parent pointers
are available.
Round 3:
• https://www.geeksforgeeks.org/sort-array-according-order-defined-another-array/
• An array of 0s and 1s is given. A sequence is given as f(1)=1,f(2)=2, f(n)=f(n-1)^2 –
f(n-2)^2.
Print 0s and 1s alternatively according to the given sequence.
Round 4:
Round 5:
• Given an array and a window k, print the minimum in every window of k. After
suggesting a few data structures like dequeue, heap, bst, he told me to code it using
bst.
• A file system is given. All the subdirectories in the root directory, the subdirectories
within subdirectories and so on is given. The input is some file or subdirectory paths
for which we need permission. Find the minimum permissions required to get all the
permissions. No file for which permission is not asked should be given permission to.
Tip:
• The interviewers are really very helpful and they keep on giving hints if you are stuck.
Just let them continuously know your thought process. It is not necessary that you
speak continuously but let them know what you think in intervals.
• They might ask you to think of better complexities and different data structures
to solve the same problem. But its not that if you straight away land up in an
optimized solution its bad for you because I was asked sometimes to compromise on
the complexity but think of other data structures to solve it.
• While coding take your time. Make sure you cover the corner cases and if it is taking
long, let your interviewer know what you are doing currently. Test it before finally
approving it. If it fails, don’t worry, tell your interviewer about it and think of a fix
or an alternative
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-203-recruit-drive/
517
Chapter 206
518
Chapter 206. Set 204 (On-Campus for Internship)
1978
answer 7 * 8
Initially I did it in O(n2) ie for each element i I found the maximum to its right and then
compare the maximum with the ith element then it can be the possible pair
and can contribute to the result
I came up with and (nlogn) solution using segment tree and sparse table
(Range maximum query) (Interviewer was impressed).
Finally I created a max stack from the right side and did it in O(n) with O(n) space but
still she wanted me to reduce the space to O(1)
It was already 1 hr and she gave me a hint that move from right side
and bingo i was able to answer her in just 5 minutes.
She was completely satisfied with my solution.
Then there was a small discussion on my projects.
Round 2
The round again began with my brief introduction and then he asked me about my favorite
subject.
He asked me to explain any data structure. I explained him Tries and segment tress. I even
told him about how tries can be used . I told him about auto complete features available,
forward dns and there working (He was impressed)
Now the he was asking questions from application point of view
He asked me about heaps and it uses and to comment upon it
I explained him heaps priority queues and complexity of it operations and about Fibonacci
heaps.
Application for merging k sorted arrays.
He asked me to illustrate some application of circular linked list and double linked list.
I told him double linked list can be used for LRU cache and using hashmap it can be done
in O(1) expected complexity per operation.
I was asked to code it.
For circular linked list I told him that it can be used for implementing a circular queue
efficiently since we need to maintain only one pointer ie. the rear for it.
Application BFS.
He then asked me to code and dry run a circular buffer and optimize it and compare it with
standard cyclic queue.
I used a counter variable for this purpose to use the buffer completely
and told him that the drawbacks can be when multiple processes try to access this shared
variable then there may be inconsistency hence traditional one was better.
Then he asked for critical section,locks ,semaphore and mutex.
All Practice Problems for Amazon !
519
Chapter 206. Set 204 (On-Campus for Internship)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-204-on-campus-for-internship/
520
Chapter 207
521
Chapter 207. Set 205 (On-Campus for Internship)
He scanned my resume and then proceeded with a brief description of my project and its
relevance.
2 coding questions
1. Maximum sum subarray
2. Maximum product subarray
covering all corner cases and proper working code
It moved on to detailed discussion on OS: thrashing, threads, processes, mutex semaphores
etc. The interviewer was nice and made me comfortable throughout the process.
Lastly, he asked if I had anything to ask him. I asked about the role of interns and latest
projects going on in the company.
Tips:
Be expressive during your interview.
Have a good resume (Aggregate+Projects+Coding skills)
Stay calm and confident
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-205-on-campus-for-internship/
522
Chapter 208
Written Exam(1hr:30mints):
There were 22 questions asked in which 20 were of MCQ’s and 2 coding questions. Most
of the MCQ’s came from OS, Algorithm, C-o/p and aptitude (directly from previous year
Computer science GATE).
First coding question: Determine the diameter of a tree (Taking input was a bit difficult as
we have to take input in array of unknown size,sort it and create BST).
Second coding question: Given a string of words seperated by comma,we have to print pair
of words who are anagrams line by line(case-insensitive). If you don’t find any such pair
then print -1.
Interview Rounds:
Round 1(1hr:15mints):
1. Started with Introduction then he jumped into project and discussed about 15 mints.
2. Given an array print elements according to frequency and if two elements have same
frequency then print it in decreasing order.
Gave solution using 2d matrix in O(n2). Then reduced the complexity by sing AVL
tree in O(nlogn).Later coded AVL tree solution on paper.
3. Given a binary tree, print boundary traversal
I gave solution by using three traversal(as given in gfg) then he asked me to do it in
single traversal. I discussed alot with him then finaly came up with solution by using queue
and stack data structure. Later he asked me code it and I coded correctly. He was impressed
with my code.
Round 2(1hr):
1. Started with project discussion of around 25 minutes.
523
Chapter 208. Set 206 (On-Campus for SDE-1)
2. Given an array of stock prices, find maximum loss in buying and selling stocks. I gave
him appoach first, then he asked me to code. Coded it.
3. Implement garbage collector in C without using free function.
4. What is virtual inheritance.
5. Explain how the file is stored in memory.
6. Explain UNIX I node Implementation.
7. Difference between process and threads.
8. How threads are executing parallely and how they share memory.
9. Asked algorithm to schedule kernal level threads(gang scheduling).
Round 3(1hr:30mints):
1. Started with Introduction
2. Detailed project discussion of around 45 minutes.
3. Given me the Resource allocation graph with set of processess and resources, ask me to
tell him the approach to execute all the process.
I told him to use topological sort suddenly he said very good and ask me to code. I
coded it.
4. Explain the need of synchronization with the help of example.
I explained him with use of producer-consumer and printer spooler problem(also written
code for both).
5. basics of synchronization i.e code for wait and signal operation and how the semaphore
maintains their suspended list.
At the end of this round interviewer was very impressed.
Round 4(1hr):
1. Given a integer number n, tell its binary representation is palindrome or not.
e.g 4=100 not palindrome
5=101 palindrome.
TC = O(n) and SC = O(1) was expected and I coded it.
2. He gave me a java code using lock on this keyword.Ask me is there any problem in
the code using lock keyword when multiple threads are running concurrently. I found the
problem then he ask me to resolve it and I resolved it.
3. What is virtual memory. Who implements it.
4. How virtual memory concept is implemented in system.
Tips:
1. Interviewer don’t expect you to give all correct answer though they want to see your
approach first and how you tackle a problem which you don’t know apriori.
2. Brush up OS fundamentals thoroughly and try to practice code on paper as much as you
can.
3. Along with basic data structures also have some idea of advance data structures like
BBST,Trie,Graphs etc.
4. Think loud in front of interviewer and try to engage him all the time.
5. Listen his words carefully, probalbly they will have some hints to answer.
I would like to thanks geeksforgeeks team for providing such a great platform. You guys are
doing awesome job.
All Practice Problems for Amazon !
524
Chapter 208. Set 206 (On-Campus for SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-206-on-campus-for-sde-1/
525
Chapter 209
526
Chapter 209. Set 207 (On-Campus for Internship)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-207-on-campus-for-internship/
527
Chapter 210
528
Chapter 210. Set 208 (On-Campus for Internship)
Round 3(F2F)
Only one question was asked in this round. She asked me to implement a data structure
that can perform
1) Insert (O(1))
2) Delete (O(1))
3) Count(O(1))
4) Get Element(O(1))
on integer inputs. Here Get Element returns any element present in DS.
I told her my approaches using array, single linked list with hashing and using two singly
linked list and hashing. I couldn’t reach exact solution but she was satisfied with my
approach.
Solution to this problem was easy using doubly linked list and hashing.
After this round a total of 19 students were selected for internship.
TIPS:
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-208-on-campus-for-internship/
529
Chapter 211
530
Chapter 211. Set 209 (On-Campus)
Round 4:-
(1 hour 15 min)
4 questions :-
1) given a number line from -infinity to +infinity what are the mnimum number of hops
required to reach a number given the condition at step j I can take j steps forward and j
steps backward
2)what datastructure to use to implement best fit algorithm , I gave a skip lists solution
which i thought was a strong solution
3)Traverse a binary tree in zig zag order – very common question
4) gven some values [M] [T] [R/W]
M- memory address
T- time slice
R/W- Read/ write
the number of conflicts were needed to be found out !
I couldn’t make it after this round –
Why I got into such a predicament was because I was to excited and was asking too many
questions and trying to discuss CS concepts which were unrelated to the problem in hand .
Only 2 tips :-
1) Geeks for Geeks is a MUST, so is GeeksQuiz
2) Speak as little as possible the interviewers would not be interested in answering your
questions with the time constraint that they have , Short discussions are acceptable but I
was trying to ask too many questions and telling them about stuff I knew without them
asking .
Thank you Geeks for Geeks for making answering amazon questions easy !!
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-209-on-campus/
531
Chapter 212
532
Chapter 212. Set 210 (On-Campus)
Give the following output without using any extra space: 1->4->6->7->2->5->8->3
Solution: Make the next pointer of D to point to down pointer of A, followed by making
next pointer of 1 to point to down pointer of B. Similarly proceed until the two heads meet.
2. Connect nodes at same level using constant extra space (expected me to write a modular
, clean and production level code)
Round 3(F2F)
1. Given a string and a pattern, Replace all the continuous occurrence of pattern with a
single X in the string. With example it will be more clear
String: abababcdefababcdab
Pattern: ab
Result: XcdefXcdX
Initial 3 occurrence of ab is replaced by one X and then two occurrence of pattern is replaced
by one X and final one occurrence of pattern is replaced by one X
Coded it incorrectly in first attempt. The interviewer gave me another chance, coded it
perfectly.
2. Print the left and right side view of the tree in a same function. (wrote a clean code with
no mistakes)
Round 4(F2F)
Asked about my projects, about myself etc etc
1. Given a stream of Twitter data with hashtags generated in time construct a data structure
to give top K trending tweets at a time.
I initially suggested max heap based on frequency but was unable to find top K nodes in a
max heap.(*Trouble)
Later, i suggested to maintain a hash table with frequency count as the value and hashtag
as key and to implement a k-size Min-Heap to store the top K elements.(She was satisfied
but not happy with the time complexity)
533
Chapter 212. Set 210 (On-Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-210-on-campus/
534
Chapter 213
535
Chapter 213. Set 211 (On-Campus for Internship)
I started out with O(r*c), then optimized to O(rlogc) and finally O(r+c).
Problem 2
Given three points in space find if a triangle exists.
Problem 3
Given four points in space find if a square exists.
Problem 4 Given points in space, how will you determine whether the points given are in
clockwise order.
All the problems required full working code for the most optimized approach.
10 students were further shortlisted for the next round.
Round 3(F2F)
We initially discussed about my project including the future course that I would like to
further steer my project in.
Problem 1 Given a Binary Tree, find if it is a Binary Search Tree with constant space
complexity.
Problem 2
Suppose there are n Petrol Stations in a circle. The difference in distance between two
stations P1 and P2 is L1 and so on and so forth.
Now, given the fact that for every unit of petrol consumed you can only walk 1 unit distance
and you can move further only for positive difference between the reserve petrol and the
distance that is to be traversed. . Find out if there is a vertex starting from which you can
come back to the same point traversing the circle once.
Expected Complexity O(n) I started with O(n^2) and gradually optimized it to O(n)
(Hint: Build a reserve array such that R[i] = P[i] – L[i])
Full working code was required in this case as well.
After this round, 6 students were selected for internship.
TIPS:
1. Stay calm
2. Remain super confident throughout. That is the key.
3. Have faith in yourself
4. Your implementation skills must be real good.
All thanks to Geeksforgeeks for helping me with my preparation and for being an excellent
repository of past Interview Sets.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-211-on-campus/
536
Chapter 214
537
Chapter 214. Set 212 (On-Campus)
Questions on OOPs concept. Asked what a singleton class is. I answered, then he asked
how can it be implemented in C++. I was weak in the C++ language, so he gave hints. I
tried but he was not satisfied with my answer.
Then he asked to a question regarding trees. Given a binary tree, you have to connect all
the nodes in each level through extra pointers.
I gave an approach using queue. He then asked how to do with constant space. I tried, but
i had forgotten the algorithm. He tried giving hints, but i wasn’t able to solve.
4th Round F2F (HR + Technical)
He started off by asking how was the other interviews. Then he asked the typical “Tell me
about yourself”.
He asked me little about my favorite project. I selected the same one which i explained in
the first interview.
Next he asked, Given just a page of a Dictionary. It can be from anywhere, middle, end
or start. The dictionary is for a language that one doesn’t know. You have to find out the
order of the alphabets, which one comes before and which one comes after. I started with
an approach using generic tree. He asked me why can’t graph be used. I thought a little
and agreed, and started using graph. I explained him the inconsistencies that can occur.
Later after few minutes of discussion, he told me, suppose he gives me a graph with letters
in place of nodes, and says to find out the order of the alphabets. How would i go about
doing it. I mentioned topological sort, but i said i don’t remember the algorithm properly.
He gave a little hint, that reminded me, and i solved it.
He gave a scenario. Suppose you type “www.amazon.com” and hit Enter. What goes on
in the background after that. I gave a detailed explanation with Network layers, routing,
CDN, Content Caching. I missed out NAT, so he asked me what it was and how it will be
used.
Then he gave me a list of list. It had integers. Like the one shown in picture below (in
Attachment).
538
Chapter 214. Set 212 (On-Campus)
He told me to print 1, 2, 3, 4… I did it using loops, But he wanted to optimize it, and said
that i can modify the list if i wished. So i thought a little and got the idea. He asked me to
write the code. I wrote, he saw and said there was a bug, but he had missed something, i
explained him, so he was satisfied with the code.
Only 7 people were there till the last round. The interviews were over by 10:40pm. They
took 3 hours to come to the final list. They said that we all did very well. At 1:30 night
they announced 3 names. I was not selected. All in all it was a good experience, but i was
a little sad after the results came out.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-212-on-campus/
539
Chapter 215
540
Chapter 215. Set 213 (Off-Campus for SDE1)
to calrify if I haven’t crammed it asked me to explain him the recursion and dry run it on
different examples. I did that explaining him completely the edge cases and every aspect of
that recursion. He was impressed �
Then he started telling about his experience of startups and that of Amazon
2.) He asked me another question :
Given a stock market price for each day in an array. Give the ans as to when you will buy
stocks and when you will sell so as to make the maximum profit.
I think for a while and gave him my approach which he was quite impressed.
After that HR asked me to leave and said that you’ll be informed about the result and
further rounds.I got a call and was asked to come for Hiring manager Round
Round 3 (Hiring Manager):
He is the manager of the team for whose team interviews are going. So he started of with
the formal discussion as to what are my technical interests and what did I learn in my
previous jobs. Then he starts discussing my CV and asked e t pick any 2 projects at which
I’m confident enough.
As I wrote technical paper on the work I did in my last job, so he started discussing over
that and asked me different ways of solving that problem and hw could I optimize it further.
Then he asked me some of the behavioral questions as of why are you leaving when such a
good work is there. I told him the concern about salary. It went fine and I thought that I
impressed him.
Later on HR told me to wait for another 4 hrs for Sr Manager round.
Round 4 (Sr Manager):
He is a very senior person in the Amazon. probably their head of some main division. He
started off with very behavioural questions as to why leaving so early and why Amazon. It
was very hard t convince him as his expressions were not changing at that time. He fired
me a series of such questions as to what is the most difficult task I have performed till yet
technically. He was hoping for answers specific to work related. What are your weakness
and strengths and what are you doing to improve yourself.
Then he jumped to my CV and asked me for each and every single detail written in my CV(
so please make your CV as small and as specific to your strong pints as you can). He asked
my role in different projects I have done and in the technical paper I have written along with
others. he even asked my college projects(even the 2nd sem project which I forgot to take
off from my CV) to the depth and asked for the specific details( He knew about everything
regarding my projects ).
Then after this discussion I thought it would get over, but he has some other plans. He
asked me to give a solution to some coding problems:
1. Check how many Parenthesis are balanced in an array of parenthesis.This was easy but
then he asked me to scale it such that your array can’t reside it on one memory. To this I
said do parallel processing, he gave me freedom of number of clusters on which I can store
and compute and then it took some time to me to come up with scaled algorithm. That
was quite interesting and energetic enough. All my tiredness went off.
2. In a string detect the smallest window length with highest number of distinct characters.
For eg.
A = “aabcbcdbca”, then ans would be 4 as of “dbca”
541
Chapter 215. Set 213 (Off-Campus for SDE1)
Finally I gave him some solution which was incomplete, he asked me to relook at my solution
and I found the mistake but didn’t asked me to code it.
I would like to thanks G4G to be such organized forum with the help of which, we can get
what are the current trends in interviews and also what they expect.
Don’t copy the solution from g4g but get the approach as that will help you to solve newer
problems ;). In other words train your model rightly, Don’t overfit it, else your accuracy
will be compromised �
Thanks.
All Practice Problems for Amazon !
Smallest distinct window
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-213-off-campus-for-sde1/
542
Chapter 216
543
Chapter 216. Set 214 (On-Campus)
a function to convert any integer between 0 to 100 to Roman numerals. All the rules for
conversion have to be followed.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-214-on-campus/
544
Chapter 217
Input: 17->15->8->9->2->4->6
Output: 8->2->4->6->17->15->9
545
Chapter 217. Set 215 (On-Campus for Internship)
Q2. What happens when you click a web address and how are web pages retrived.
Q3. He asked me about memory management in C and C++ and how new allocates memory
to objects and he asked me to overload new operator.
Q4. If you are given some functions and whenever you call that function,the timestamp is
stored along with function name.
eg: f1 1:20
f2 2:30
f1 3:10
Suggest an appropriate data structure and write a code to make following queries within
two given time stamps t1 &t2:
query 1: Return number of all the functions called between t1 & t2.
query 2: Return number of times a particular function is called between t1&t2.
Then he asked me various OS and networking Questions.
Q5. Given an array of integers,find a subarray having least average.
Q6. Suggest some data structures to maintain relationship between various hierarchies in
an organization.
Thanks to geeksforgeeks for helping me out.
Read Geeksquiz for MCQs & g4g for interview questions.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-215-on-campus-for-internship/
546
Chapter 218
Source
https://www.geeksforgeeks.org/amazon-interview-experience-216-on-campus-for-internship/
547
Chapter 219
548
Chapter 219. Set 217 (On-Campus)
TIP: Interviewer should understand your code properly. So write code neat & clean.
***** Third Round (F2F) (70 min approx.)****
1) Again the interviewer ask the same question: Find the next greater element in array. I
told him that I did it previous round then interviewer tell me that it is good u told me
about this.
I think I got some loyalty point from this �
2) Given the mathematical expression. Check for balanced parentheses in an expression
with constraint of precedence like
[2*{3+4}] = True;
{2*[2+4]} = False;
I give him approach and written full code for this.
3) How to detect cycle in graph ( I just told my approach using DFS)
**** Fourth Round (F2F) (120 minute)*****
1) Consider a row of n coins of values v1 . . . vn, where n is even. We play a game against
an opponent by alternating turns. In each turn, a player selectseither the first or last coin
from the row, removes it from the row permanently, and receives the value of the coin.
Determine that the user move first or second so that he will get the maximum possible
amount of money
I gave him the recursive approach for this then he ask for optimize code for this then I make
DP for this.
2) Consider a 2-D map with a horizontal river passing through its center. There are n cities
on the southern bank with x-coordinates a(1) … a(n) and n citieson the northern bank with
x-coordinates b(1) … b(n). You want to connect as many north-south pairs of cities as
possible with bridges such that no two bridgescross. When connecting cities, you can only
connect city i on the northern bank to city i on the southern bank.
I have no idea about this question I think 10 minute and told the interviewer that I’m
unable to solve this. But the interviewer asked for my approachthen I gave him brute force
solution for this and Interviewer asked for the code. Then he told me to optimize the code
then I gave recursive approach for butstill complexity is exponential and Interview asked
me optimize this and again I think for half an hour &arrive at solution that in DP with
extra space. Buthe still wants better solution and gave me five minute more. Then in the
five minute one best solution strike in my mind and told to interviewer and he ishappy with
effort then he ask to code.
TIP: What I learned from this round is that Push yourself to the edge. Give something
different or better than geeks
***** Fifth Round *****
1) Some project discussion in brief and some question on project like what is your role, what
difficulties you faced, and future scope.
2) Find minimum height of tree (I gave him two approach using 1) simple 2) using level
order)
3) Some simple Bit-masking problem
549
Chapter 219. Set 217 (On-Campus)
4) Given an input file with four billion non-negative integer. Provide an algorithm to
generate an integer which is not contained in the file. Assume you have 1 GB of memory
available for this task.
Firstly I have no idea then interview is giving me hint and I give my approach using bit
vector by mapping all integer from this bit-vector.
***** Sixth Round ****
1) He give me an API function that increment the counter when the client access this. And
told that two client simultaneously accessing this API function. Then they get ambiguous
value of counter. Why this is happening?
I give him Peterson solution and semaphore solution for the critical section problem.
2) Some more question on OS (thread, Mutexlock, and deadlock)
3) One more DP Ques: Remove minimum elements from either side such that 2*min becomes
more than max.
I gave him geeks solution but he ask that Have u seen this problem before? I said yes then
he ask to code the recursive approach for this I write it
Correctly. And He was satisfied.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-217-on-campus/
550
Chapter 220
551
Chapter 220. Set 218 (On-Campus)
First I have given the recursive solution than interview asked me dp solution, I told him DP
approach he was satisfied.
5) Find Loop in a linked list and remove it.
6) You have 100 songs to play in a shuffling mode how will you play.
Interview want full working code for each question for last question he wanted only approach.
***Third Round (F2F):(1 hr)
1) Given a source string and a destination string and a dictionary consisting of various words
write a program to find minimum length path to travel from source to destination. Rules
for traversing:
1. You can only change one character at a time
2. Any resulting word has to be a valid word from dictionary
Example: Given source word CAT and destination word DOG , one of the valid sequence
would be
CAT -> COT -> DOT -> DOG
Another valid sequence can be
CAT -> COT – > COG -> DOG
One character can change at one time and every resulting word has be a valid word from
dictionary
I told him a approach using graph.
2) What is hashing.
3) What is modular hashing.
4) How collisions can be handled.
5) Is semphore guarantee deadlock prevention.
*** Fourth Round (F2F) : (2 hr)
1) A kind of celebrity problem you have n person where one of them is celebrity
condition are all non-celeb person knows celebrity and celebrity can know few other persons
and all non- celeb persons can know few of them among each other so you have to find
celebrity.
2) Given a binary tree and two nodes print the path between the two nodes of binary tree.
3) Find Height of Binary Tree represented by Parent array
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-218-on-campus/
552
Chapter 221
553
Chapter 221. Set 219 (On-Campus)
while coding I found it was the wrong one, I told him that this approach wont work. At last
he said to leave this problem n moved to next.(only questions I couldn’t solve)
6.find loop in LL.
7.find frequency of words in a paragraph I suggested at first a hash than trie n he was
satisfied with the answer.
8.Again a short discussion on the project.
Round 3(Design questions) (1.5 hr)
1.) Suggest auto correct if a word is misspelt.
i)only one character is replaced by wrong character like cht then suggestion can be cat.
ii)the word written is prefix of other word.
Used trie.
2.) A service is requested by fixed number of customers (limited 5-10 ). If the service fails
at time n. Find frequency of requests made by each customer 10 minutes prior to failure of
service. I suggested a DS made up of queue and map.
3.)given a set of classes and their dependencies, return if this given set can be
BUILD(compiled) with or with out error.
class A:B C
class B:D
class C:E F
class D
class E:A
class F:G
class G:A
return error as classes A,C,E depends on each other.
I said questions same as find loop in a graph he agreed n asked to code.)coded it)
round 4(subject round)(2hrs)
1.)The answer sheets of previous interviews are passed on to next interview as my 3rd
interviewer did not had my answer sheet of 2nd interview he asked me about the questions
asked to me in the last interview.
2.)consider a service running on a server for a customer c1,but customer c1 times out after
s sec for what so ever be the reason so customer again fires the same request ,so server is
running duplicate query hence it gets overloaded, resolve this glitch. Some how I managed
to give a solution which he said is very similar to the solution he himself implemented to
resolve this glitch.
3.)given a tree find sum of all the numbers formed by appending the data of nodes from
root to leaf node. In a single traversal of the tree.
Eg:
1
/ \
2 3
Return 12+13=25
554
Chapter 221. Set 219 (On-Campus)
I solved it using a reference variable to store final solution and an variable passed as value
to store up to current node*10,thus add data of current node to this variable to get number
formed till this node if current node is a leaf then add it to variable passed as reference.
4.)Any idea about scheduling algorithms and there types.
5.)Given a matrix of 0’s and 1’s,find the maximum size of the square formed by 0’s.
1111
1000
1001
0000
Return 2.
coded it by flipping all zeros to ones and ones to zeros than ques similar as given on GFG.
6.)what is mutex?
7.)given words of a lexicographical order of an alien language find order of characters in the
language.
I said I have seen this problem it is of topological sorting and he proceeded to next question.
8.)multiple producers single consumer problem.
9.) Find all possible interpretations of an array of digits. I proposed a solution I was asked to
code it I coded it but he pointed out an error for test case containing zeros like 10,20,2010,so
I handled the case of zero.
Round 5(45 min)
1.)I was asked to tell about my projects which was not the one I discussed in first round
(either they had an discussion about it prior to my interview or coincidence).
2.)I had one project on web crawler so I was asked what changes will you make to this
project to scale it.
3.)another project was an android game similar to duck shooting(video game) was asked to
tell the difference between the 2.
4.)I was asked to tell how to copy last 10 lines from a file, he kept on asking for other
methods (I answered around 10 different ways).
5.)add and subtract two numbers without using + or – operator.i was asked to code it.i
used xor and binary and to solve it, then he asked to prove this method works.
7.)convert 777 to binary.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-219-on-campus/
555
Chapter 222
Ques1: An array containing heights of building was given. Its a rainy season. Calculate the
amount of water collected between all the buildings.
Input: 1 5 3 7 4 2
Output: 2
Ques2: Two strings are given check if anagram of one string is contained in other string.
556
Chapter 222. Set 220 (On-Campus)
complexity and O(1) extra space. Told him that I know its approach already. He asked me
for the approach.
https://www.geeksforgeeks.org/find-the-two-numbers-with-odd-occurences-in-an-unsorted-array/
Ques3: An array of size n-1 is given contains numbers from 0 to n. Find the two missing
numbers in O(n) time and O(1) space. Suggested him method given in :
https://www.geeksforgeeks.org/find-the-smallest-positive-number-missing-from-an-unsorted-array/
557
Chapter 222. Set 220 (On-Campus)
Unsigned inti;
For(i=100,i<=0,–i)
Printf(“%d\n”,i);
Ques 3: What happens when you hit your college url. Describe all steps. Then he asked
some questions on networks like http, tcp, port, switches etc.
Ques 4: Print all permutations of a string. Asked me for the approach and code it.
Round 5(F2F 4):
Long discussion on my summer internship project. Project was on “Machine Translation”
(translation of one language document into other language). Mine was converting English
to Hindi. Asked me for the approach and discussion on the same.
Then he gave me this problem.
There are number of clients requesting pages of a service. Find number of pages requested
by clients in each 5 minutes. Gave a solution with queue using linked list and map.
Then a long discussion on my minor project which was on machine learning. The interviewer
was having deep knowledge on machine learning So he asked me a lot on the same. Then
he asked me if I have studied it as a subject. I said no. He said “that is what I wanted to
know”. He was impressed with my projects.
Hope this experience would help you to prepare for the company. GFG helped me a lot, a
great site with almost all stuff to prepare for the interview. Best of luck J keep coding J
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-220-on-campus/
558
Chapter 223
Set 221
559
Chapter 223. Set 221
Online mcq, there were around 20 and 13-14 were from geeksquiz.com
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-221/
560
Chapter 224
Set 222
• Given an array having positive and negative numbers. Rearrange the array in such a
way that positive and negative numbers are then alternate
Eg – Input : { -3, 1, 5 , 7, -4, -7, -6} Ouptut : {-3, 1, -4, 5, -7, 7, -6} (Question
demand;ed that order of the elements should not change)
A similar question is given in geeksforgeeks with O(1) space but that uses quick sort
concept which is not stable and hence order gets changed in many test cases.
I used simple approach of dividing array in two parts of positive and negative numbers
and then merging them one by one which worked.
• Convert a tree into it’s sum tree
https://www.geeksforgeeks.org/convert-a-given-tree-to-sum-tree/
Interview:
Round 1:
• Create links in an N-ary tree(N not fixed) into a tree where children of every node are
having next pointer connected to it’s siblings in a spiral fashion.
561
Chapter 224. Set 222
Also on level 1 right most node’s next pointer should point to level 2’s right most node
and in spiral way taking upwards root’s next should point to left most child.
I used two stacks to do the problem. The interviewer asked me to code it, I couldn’t
complete but she was convinced with my approach.
Round 2:
• It had easy questions, maybe they wanted to check coding skills for known problems.
And also asked about projects.
• Given two strings then check if they are anagrams or not. (Character set is not just
26 alphabets it can special symbols like $ % ! )
Also if strings have spaces then also they are anagrams like “adf ds” & “addfs” are
also anagrams. I implemented it in Java using HashMap.
• Given two sorted linked lists, merge them into one linked list (Both iterative and
recursive code)
Round 3:
• Tell me about your favorite subjects. I told Data structures & Algorithms , Number
Theory & Cryptography. He asked me about different attacks possible on a website
page. And asked me about what is man in the middle attack. Maybe he just wanted
to check my knowledge on my areas.
• There is a society which has 8 parking slots and there are 7 cars. Each car is supposed
to be parked in some fixed position and one slot is needed to be left.
Example – Let { A ,” “, D, E, B, F, G, C} be the perfect arrangement. But society
people never follow the rule and park in any position. Your work is to design a strategy
which arranges the cars in perfect arrangement at the end of the day having minimum
number of swaps. I was able to solve only this one question in this round. I used to
strategy that :
1. I’ll first find the empty slot and will check if there is some car should be placed in
that place properly and will swap the car.
2. In case the empty slot is at correct position then I’ll find an improperly placed car
and place it at empty slot and then will continue with step 1 iteratively till I get the
perfect arrangement.
Round 4:
This was the round with main person who had come with Amazon team. He was
taking interview since morning and had seen me with my friends discussing about interviews
conducted by him. It was 7:30 in evening when my interview was about to start so while
going to room in lift he asked me that if I know any of his questions. I honestly told that
yeah I know about a few. He asked me about them and their solutions. One was similar to
question 2 of round 1. Another was arranging a list of lists. He said that he will ask new
questions now �
562
Chapter 224. Set 222
• Again a modification of binary search : Ex : {c,f,k,v} Now given an input for element
we have to print the element next to it in array (even if it is not present)
Input Output
a c
c f
j k
v c
Then he asked simple question of finding maximum sum subarray (Kadane’s algorithm). I
did it very quickly so he asked another question to find next greater permutation. I gave
the algorithm and coded it.
Final question he asked that like in github when we save a code it makes commit points. So
if some code has been saved multiple times and has many branches divided and then getting
merged. We have to find the least common parent of two given commit points.
It is similar to a linked list which is getting divided and then getting merged again number
of times.
I have a table given for parents of a node in chronological order and we have direct access
to parents too.
Ex – In this case
Node – J I H L K G F D E C B A
Parent – I H G K G F D,E C C B A NULL
Given if I/P is (H, L) the output must be G. It seems similar to LCA concept of trees but
it is a slight modification of it. I told about concept of stack that I’ll search for given nodes
and will then store in two stacks and will pop till I get same value from stack. This popping
I’ll do according to information of table of node- parent.
I was not able to complete it but was able to show my approach and I handled the corner
cases. He was satisfied with it.
• I suggest that always listen carefully to interviewer, they’ll definitely help if you have
any doubt. Tell them your approach at least if you are not able to code it. Practice
writing code on paper. Be very careful while you tell about projects. They may get
563
Chapter 224. Set 222
very interested in your projects and it will be very helpful for you. For Amazon Arrays,
Linked Lists and Trees are concepts which are very generally asked. Data structures
& algorithms should be proficiently practiced. Thanks a lot GeeksforGeeks � �
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-222/
564
Chapter 225
Second round:
1. find the area of largest possible rectangle from the given histogram.
2. print the boundary leaves of a binary tree.
some 20 odd people were selected.
Third Round: Technical Interview.The interviewer is my college pass out. He asked me
about my projects very briefly. Then he asked two questions.
1. Given a number give the count of all possible words that can be formed out of it taking
the digits continuously. time complexity O(n).
2. print the level order traversal of binary tree
Fourth Round: Technical interview. three questions were asked
1.find the maximum element in a sorted rotated array.O(logn)
2.print all the pairs of numbers that sum up to K in a given BST. O(n)
3. sort all the one’s and zero’s to opposite sides.O(n)
Fourth round: basic questions on os,dbms, networks.
565
Chapter 225. Set 223 (On-Campus)
Since I had some projects he asked me questions on cloud, and based on my answers the
topic got drifted towards distributed computing, etc.
Next round was HR interview.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-223-on-campus/
566
Chapter 226
Set 224
567
Chapter 226. Set 224
the end there are no digits remaining then return the total number of segments, -1 otherwise.
Need to start with 5^1 and go up to the max power of 5 that is less than the string.
Had to write proper code for this problem covering all edge cases.
3) Given n people and n+1 parking slots. Each person has a car and a parking slot allocated.
One night they all go to a party and get drunk. They end up parking their cars randomly.
What’s the best way to go back to the initial configuration (one where every car is in the
right allocated slot). (N+1)th parking slot can be used to swap the cars.
Only algorithm was needed for this problem.
Come up with a sorting algorithm with nlog(n) complexity.
Hint: Use Java’s comparator class to solve the problem.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-224/
568
Chapter 227
For eg:
a) Insert 25 in 10->20->30->40->50->10-----
o/p : 10->20->25->30->40->50->10----
b) Insert 60 in 10->20->30->40->50->10-----
o/p : 10->20->25->30->40->50->60->10-----
569
Chapter 227. Set 225 (For 1 Year Experienced)
cells sharing the same state as the given cell toggles and the effect cascades. Represent the
final state of the matrix.
3) Given a deck of n cards, in each iteration the top card is removed and pushed to the end
and the second card is removed from the deck. For eg: In 1st iteration, 1st card will added
to the end and 2nd card will be removed, again 3rd card will be added to the end and 4th
card will be removed and so on. Find the last card which will be remained.
Face to Face Round 2 (Technical ~ 1:30 hours)
1) Given a boolean matrix with every row sorted, find the row with maximum number of
1s.
2) Given a paragraph and two words A and B, find the minimum distance between a occur-
rence of A and B.
3) Given two valid three letter dictionary words, find the minimum number of steps required
to transform first word to second word. Following are the transformation rules –
a) You can, in a single step, change a single letter in the word.
b) Each transition should result in a valid word. Assume you have been provided a helper
function boolean isValid (String word) which tells you if a word is valid or not.
c) This must be done with minimum transitions.
Example: Transform CAT to TOY. One of the several possible transformations is CAT ->
CAR -> TAR -> TOR -> TOY
4) Sort a linked list which is in alternating ascending and descending orders.
For eg :
10->60->30->40->50->20 to 10->20->30->40->50->60
5) Find the next greater element for each element of an unsorted array.
Some Computer Science Fundamentals now :
1) Explain what happens in the background when you enter “ls” command on unix shell.
2) Difference between process and threads.
3) What is semaphore and mutex. What is Readers-Writers problem? Explain solution with
code.
4) Difference between TCP and UDP.
Few more questions which I don’t remember now.
Face to Face Round 3 Fa(Hiring Manager ~ 1 hour)
1) Tell me about yourself.
2) Why do you want to change your current company? Why Amazon?
3) Tell me about your current Projects. What is your role? Tell me architecture of this
project.
4) Scanned through my resume and asked about everything mentioned in it.
5) Design question : Design an autocomplete library for a keyboard in a mobile device which
does following tasks:
a) Autosuggest words while typing from the inbuilt dictionary.
b) Suggest words based on your previous inputs:
For eg: If you frequently type “Thank you”, so if you type “Thank” then your library should
suggest “you” as first result.
570
Chapter 227. Set 225 (For 1 Year Experienced)
I was asked to tell which data structure would I use and write classes and ethods for this
library.
Face to Face Round 4 (Bar raiser ~ 1:30 hours)
This round was taken by two guys from different teams and both of them were bar raisers
of their respective teams. I was asked to use the whiteboard in this round.
1) Both of them gave a brief description about themselves.
2) Tell me about yourself.
3) Why do you want to change your current company? Why Amazon?
4) Tell me about your current Projects. What is your role? Draw the architecture of this
project.
5) Then one of the interviewer gave a C code snippet and asked me what this piece of code
does?
What the problems that you see in this code?
6) Connect all the siblings node in a binary tree.
Follow up questions:
a) Now connect all the non-siblings nodes as well (basically connect all nodes at the same
level). ( cousins )
b) Now write a recursive solution of the same.
I took a long time in coming up with the recursive solution for this question, but eventually
solved it.
For each question I was asked write production level code.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-225-for-1-year-experienced/
571
Chapter 228
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-226-on-campus/
572
Chapter 229
Amazon Interview Experience | Set 227 (On-Campus for Internship and Full-Time) - Geeks-
forGeeks
This year our college kicked off placement season with the Amazon. We got the job descrip-
tion(JD) before the placement process. We got good news that Amazon have increased total
CTC. With this good news it also added tension and pressure.
Day 1: Coding and aptitude round
Coding round was at 5pm so from morning I had revised very basic things like sorting
techniques, B Tree, AVL tree, finding the power set and some DP questions.
Online coding exam was of two hours and was on HackeRank. There were 20 multiple
choice questions and two programs. Multiple choice questions were GATE type questions
mainly from OS, data-structure , algorithm, database and C. My plan was to attempt these
questions as early as possible and starts programming but questions were lengthy and it
took 30 mins. After 30 mins there were 3 to 4 questions which I skipped and started
programming.
Program 1: Anagram
Two words are said to be anagram when one word can be converted into another
word by shuffling/rearranging characters. Given a set of words find the number of anagram
for each word in given set of words.
Program 2: Find diameter of binary search tree in O(n) complexity.
Given the set of integer values, insert these values in the binary search tree and find
diameter of the tree.
Both the program were easy. I solved program 2 correctly in O(n) and second program in
O(n^2). Result was on next day so all of us were in tension. I could sleep only 3 hours :p.
Day2: Interview process
Interview Round 1:
Question 1: First question in first round of interview was how to insert node in binary search
573
Chapter 229. Set 227 (On-Campus for Internship and Full-Time)
tree using recursion and without recursion. He asked me to write the code of both.
Question 2: Given a binary tree how to find the least common ancestor of two nodes in the
tree.
Question 3: Given a binary search tree find the least common ancestor of the two nodes in
tree. He asked me to write the code of this program as well.
Question 4: He asked about projects it has taken almost 10-15 mins.
Time: 45 mins.
Interview Round 2:
Question 1: He asked me to tell about my self. During introduction I mentioned about my
previous company’s project. He asked next question about that project. I had worked on
that project almost 2 years so I could explain him that project in detail. He asked to write
the code for the Wait And Signal method of the counting semaphore.
Question 2: Given an array with -ve as well as +ve elements find max continues sum.
This question was easy.
Question 3: Given a singly circular link list containing both +ve as well as -ve numbers
find max continues sum. I explained him O(n^2) algorithm but he was asking O(n). I was
not getting answer of this question. I worked on this for 4 to 5 mins but I was not getting
perfect answer so he gave hint by drawing all elements on the circle. As soon as I saw circle
I got answer, I told to break the ring from most -ve number and then use normal algorithm
which was in 1st question. He was not sure about this algorithm he tried to break this by
using 4 to 5 example but he could not. He was happy after this answer because might be
he had another solution in his mind.
Question 4: Given prices of stocks per day find maximum profit you can earn by buying
and selling shares. You can make only one transaction.
This question is easy and from geeksforgeeks.
Question 5: Given prices of stocks per day find maximum profit u can earn by buying and
selling shares. You can make multiple transactions. He asked me to write the code of this
program.
Time: 1 hour 10 mins.
Interview Round 3:
Question 1: He saw my resume and asked me which project I find most difficult. I told
same office project. He asked me which part of that project I find most difficult. I told
part related to the scheduling. He asked me basic questions related the scheduling and
synchronisation.
Question 2: What is copy constructor in CPP
Question 3: Explain the LRU cache technique and how to implement it. I gave various
approaches like array, queue , stack, Link list. finally He agreed on Link List with hashing
approach. All other approaches were O(n^2) solution but Link List with hashing approach
is O(n). He was happy with that answer.
Link-List with Hashing approach:
Size of LinkList will be size of cache. Data in list represent page number of cache. Before
running algorithm we will build Hash Table. Key of HashTable will be page Number and
574
Chapter 229. Set 227 (On-Campus for Internship and Full-Time)
value will be address of the node in link list which contains key. One pointer to Link List
represent the most recently used page(Front of Link List) and one pointer will point to
least recently used page(End of Link List). When new page come then we will get node
containing page number directly from hash table in O(1). After getting that node move
that node to the front of link list which represent most recently used page. If the new page
not present in the Hash Table then update the value in page pointed by least recently used
pointed and move that page to front. and also update key in the hash table.
Here we are building hash only one time and not modifying its values after that.
Time: 50 mins
Interview Round 4:
Question 1: He asked about projects. I explained him my project in details which took
around 10-12 mins. During explanation he was asking like why u have used this approach
why not other and like that.
Question 2: Given n Runways and m Planes. How you will efficiently design this scheduling
problem so that there should not be collision. I explained this by giving view of CPU
scheduling problem and semaphore.
Use priority based Scheduling where priority can be departure time and emergency. Each
plane use runways as below:
Plane Pi:
Wait(S)
Take off(M.E.)
Signal(S)
S=n
Question 3: This was easy question. Given matrix which is sorted, row wise as well as
column wise like below:
01 04 07 09
11 23 45 46
51 56 59 63
70 73 75 79
and key. Find the position of key in given matrix efficiently. I explained the solution which
is in O(log m)+O(log n). He asked me write the code this problem.
Question 4: He asked very basic questions of database. After that he asked me what is
eventual consistency. I didn’t knew answer of this so I told that I don’t know, He again
asked that do u know about NoSQL I said no.
Time: 45 mins
Thanks to my parents, teachers, friends and GeeksForGeeks.
All Practice Problems for Amazon !
575
Chapter 229. Set 227 (On-Campus for Internship and Full-Time)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-227-on-campus-for-internship-and-full-time/
576
Chapter 230
577
Chapter 230. Set 228 (On-Campus for Internship)
2-https://www.geeksforgeeks.org/find-if-there-is-a-sub-array-with-0-sum/
I knew its solution and answered the best solution immediately. He asked me if I had done
the question previously. I told not exactly same but I like competitive coding so I have done
similar question. Then he extended this question and asked to print all sub-array with some
some zero.(write proper code).
Then he discussed corner cases I told some then he gave some hint and after that I got the
idea so, answered all corner cases.
Some questions asked from my friends->
1-https://www.geeksforgeeks.org/write-a-c-program-that-given-a-set-a-of-n-numbers-and-another-number-x-determ
2-https://www.geeksforgeeks.org/find-a-pair-with-given-sum-in-bst/(expect inorder and
reverse inorder solution)
3-https://www.geeksforgeeks.org/maximum-width-of-a-binary-tree/
4-https://www.geeksforgeeks.org/next-greater-element/
5-https://www.geeksforgeeks.org/print-a-given-matrix-in-spiral-form/
Note- Same questions were asked by the same interviewer to many candidates so it is advis-
able to share questions with friends as they select you for next round only if you have done
both of the questions.
9 people were shortlisted in this round.
Round 3(nearly 2 hours)-
1-Given a stream of number how you will maintain top 10 element. Whenever asked, the
answer should be top 10 element till now. (answered in 2 min using min-heap).
2-https://www.geeksforgeeks.org/given-sorted-dictionary-find-precedence-characters/
very tough question. In 1 hour with the hint of interviewer I was able to answer this.
3- Some basic C questions – What is difference b/w Malloc, Calloc. Scenario when to use
which one.
578
Chapter 230. Set 228 (On-Campus for Internship)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-228-on-campus-for-internship/
579
Chapter 231
580
Chapter 231. Set 229 (On-Campus for SDE)
Technical Interview 3:
1. Given a threaded binary tree with all the threads pointing randomly anywhere, fix all
the threads without using any extra space.
2. Questions on operating system, DBMS, automata theory etc.
Technical Interview 4:
1. Given a binary matrix (A matrix consisting of only 0’s and 1’s), where 1 represents land
and 0 represents water, Find the number of islands.
2. Given a paragraph and a sentence, find the smallest sub-string in the paragraph which
contains all the words in the sentence, return the smallest starting index of the occurrence
of such sub-string if there exist more than one sub-strings of the same smallest length.
Project based questions were also asked in between all the interviews.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-229-on-campus-for-sde/
581
Chapter 232
582
Chapter 232. Set 230 (On-Campus For SDE)
It was an easy round and 5 students were selected for Third round.
Third Round(Technical):
1.Write a program to remove the whitespaces from a given string.
First i told him in o(n) time complexity and o(n) space complexity approach but he wanted
o(n) time complexity with constant space complexity. I was unable to do it so he asked me
second question.
https://www.geeksforgeeks.org/remove-spaces-from-a-given-string/
2.Write a program to find the element which is common in all the rows in a two-dimensional
array. I told him using binary search but he wanted more optimized approach but i was
unable to do so.
I did not get selected but Overall it was a good interview experience.
I want to thank geeksforgeeks for such a good and amazing solutions to the back-breaking
problems which helped me in the interview .
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-230-on-campus-for-sde/
583
Chapter 233
1. Given three huge numbers, each represented using a linked list (where each node of
a linked list represents a digit), calculate the sum of the numbers and return back
the number in the form of a linked list. For example, 9->2->3, 4->6 and 2->5->1
representing numbers 923, 46 and 251 respectively. The result should be 1->2->2->0.
This can be solved using stacks.
2. Given a graph, detect if it has a cycle. We can perform a dfs here.
584
Chapter 233. Set 231 (On-Campus)
Given a somewhat sorted array where the numbers are in ascending order first and then
follow a descending order, find the index at which the order changes and return the number
at that index. For example, i/p: 1234532, o/p: 5. I wrote down a modified binary search
for it (had to take care of some corner cases). The interviewer was satisfied and I was sent
to the next round.
585
Chapter 233. Set 231 (On-Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-231-on-campus/
586
Chapter 234
Amazon Interview Experience | Set 232 (SDE-1 for 1 Year Experienced) - GeeksforGeeks
Interview 1:
Before the interview began we were asked to solve 6 questions
In the first interview i was asked how i solved Q4) replace all spaces with ‘%20’ and Q6)
nth node from the end of a linked list.
and then we discussed in details about a project I did with my previous employer.
and then He asked a few questions ->
Q1) Dynamic Programming | Set 21 (Variations of LIS) – GeeksforGeeks -> 1. Building
Bridges: Consider a 2-D map with a horizontal river passing through its center. There are
n cities on the southern bank with x-coordinates a(1) … a(n) and n cities on the northern
bank with x-coordinates b(1) … b(n). You want to connect as many north-south pairs of
cities as possible with bridges such that no two bridges cross. When connecting cities, you
can only connect city i on the northern bank to city i on the southern bank.
Q2) Write a C program to print all permutations of a given string – GeeksforGeeks -> Print
all permutations of a string
587
Chapter 234. Set 232 (SDE-1 for 1 Year Experienced)
Q3) Given the arrival and departure time of various trains in a station. Calculate the
minimum number of platforms required such that no train has to wait for another train to
vacate the platform.
The question basically means calculate the maximum number of trains that would be present
in the platform at any given time.
Answer
sort the arrival time and sort the departure time, keep a count initialized to 0. compare the
first element of the arrival time with the first of departure, increase the value of count if the
value at current Index at arrival is less than the value index at departure and increment the
arrival index, and vice versa. Keep the maximum count that you see.
Round 2
Q1) given the x,y,z coordinates of a billion stars (basically the entire array can’t fit in the
RAM) calculate the k closest.
Answer -> use a max heap that contains the k minimum distances.
Time-> n(log k)
then the question was changed to -> now that we have several computers which can combine
to fit the entire set of stars, how will you then solve it?
Answer-> use selection algo (similar to step 1 of quick sort) to find the k closest stars in
each of the computers. Time -> O(n) and then use the k in the those m computers to find
the minimum k. One way is to sort all them individually. and then create a min heap to
calculate k minimum.
O(k^2 log k)
Q2) Symmetric Tree (Mirror Image of itself) – GeeksforGeeks -> How to check if the tree
is the mirror of itself
Then the question was extended to a n-ary tree.
Answer -> Please read the above link before reading this answer– We create a the n ary
tree like this->
struct node{
int data;
vector < struct node* > child;
}
Round 3
Q1) Write a C code to evaluate an expression tree.
Answer-> It has to be done in a post order traversal method, since the value of the left
subtree is independent of the right subtree.
Q2) Articulation Points (or Cut Vertices) in a Graph – GeeksforGeeks -> Check for Artic-
ulation points
588
Chapter 234. Set 232 (SDE-1 for 1 Year Experienced)
For example
when we get 1,3,5 the hash map is
1 0
3 1
5 2
key is the number and the value is the index where it occurs.
when we get 4, we have to check for the index of 3 and 5. (One above and one below)
the value at 3 is 1 and 4’s index is 3, so they can’t be paired.
We then check for 5. 5’s index is 2 and 4’s is 3, since they are together, they can be paired.
1 0
3 1
5 2-3
4 2-3
and then we check for 3 again, 3’s index is 1 and 4’s index is 2-3, so they can match
1 0
3 1-3
5 1-3
4 1-3
We go on. I don’t think I answered the questions the way it was asked, but he seemed ok
with the answer I gave.
Next he modified more to include distributed systems in it. And asked me if there were
several systems which received the input in round robin manner, how would I implement
the above algorithms. I had no idea about this.
After round 3, I was called by Amazon and told that my first two rounds were positive but
round 3 wasn’t. Round 3 was the hiring manager round, and he wasn’t happy that I had
little idea about RAID ( Standard RAID levels – Wikipedia, the free encyclopedia )
So I had another hiring manager round.
Round 4
https://www.geeksforgeeks.org/find-a-pair-with-given-sum-in-bst/
Find a pair with a given sum in a bst
more questions on what happened in Round 3 and why I want to leave my current firm.
Round 5 (Bar Raiser)
Questions like
1) tell me a time when you had a different opinion than the rest of the team.
589
Chapter 234. Set 232 (SDE-1 for 1 Year Experienced)
2) tell me a time when you were thinking that the problem is something else, but it turned
out to be something else
3) tell me a time when your opinion were discarded.
4) tell me a time when you had to work on a very short notice.
Coding questions-
1) given that we can form packs of 6,9 and 20 pens. Given a number x, calculate if we can
form combinations of packs to form those many pens. Eg 24 pens can be formed by having
2 packs of 9 pens and 1 of 6 and 23 pens can’t be formed.
Answer
Dynamic Programming with the recursive function
DP[i]=DP[i-6]||DP[i-9]||DP[i-20];
2) Design an escalator system. Which classes would you make, etc.
After Round 5, they didn’t find me a cultural fit so they conducted a Round 6.
Round 6
Questions like- tell me something about yourself,
a time when you helped someone
A time when you shared a different opinion from your manager.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-232-sde-1-for-1-year-experienced/
590
Chapter 235
Amazon Interview Experience | Set 233 (1 Year Experienced for SDE-1) - GeeksforGeeks
I recently had interviews with Amazon.com, Bangalore.
Here’s my interview experienceCoding round (1 hour):
1. Find minimum number of coins that make a given value
Given a value V, if we want to make change for V cents, and we have infinite supply of each
of C = { C1, C2, .. , Cm} valued coins, what is the minimum number of coins to make the
change?
2. Suppose you have given two strings S1 and S2. Find out if S1 is substring of S2. If S1 is
present in S2 return starting index of S1 in S2 and if not present return -1.
3. https://www.geeksforgeeks.org/find-two-rectangles-overlap/
Face to Face Round 1 (Technical ~ 1 hour)
1. https://www.geeksforgeeks.org/reverse-alternate-k-nodes-in-a-singly-linked-list/
2. https://www.geeksforgeeks.org/length-of-the-longest-valid-substring/
Face to Face Round 2 (Technical ~ 1 hour)
1. https://www.geeksforgeeks.org/design-a-data-structure-that-supports-insert-delete-search-and-getrandom-in-con
2. https://www.geeksforgeeks.org/bottom-view-binary-tree/
3. https://www.geeksforgeeks.org/dynamic-programming-set-18-partition-problem/
591
Chapter 235. Set 233 (1 Year Experienced for SDE-1)
For each question I was asked to write production level code. I had to wait for 2 days for
the results. I got selected. Thank you geeksforgeeks !!
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-233-1-year-experienced-for-sde-1/
592
Chapter 236
Round 3:
a) pow(a,n) function – recursive, iterative
b) Given list of cities, find the number of tour combinations (not permutations)
c) BookMyShow design
Round 4:
a) Questions on Projects
b) next hight number with same digits
Round 5:
a) Given stream of numbers, at any point of time, need to print first non-repeating digit
b) News paper & Magazine subscription design.
All Practice Problems for Amazon !
593
Chapter 236. Set 234 (For SDE-II)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-234-for-sde-ii/
594
Chapter 237
Set 234
595
Chapter 237. Set 234
———————————————————————————————————-
Senior Manager round
Time 5-30 PM.
1. 1 byte stream which contains single byte character and double byte character
single byte can by identified by checking MSB as 0. and double byte MSB as 1.
you are at end of a character. find the previous character ( is single byte or double byte)
solved the above problem by taking Manager help
————————————————————————————————————————
———–
HR told me that HR from Chennai will contact me.
I waited 2 days and sent mail to HR about the hiring status. He replied saying that “Working
on updated. Will get back to you”.
1 week and 1 day over no idea about the hiring status.
————————————————————————————————————————
———————–
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-234/
596
Chapter 238
Round 2:
Again, the next interviewer explained briefly about himself and asked about me and my role
in the current project. He asked more details about current projects
1. Given an array of stock values of a company. Find out the time when a user would have
bought the stock and sold the sock. Basically find the maximum positive difference of
any two given elements in an array?
2. Told me to write this program.
Round 3:
Interviewer introduced himself and asked about my details and my current projects.
1. You have a BST and you need to assign an appropriate value to neighbor of all nodes
(Explained in below example)
Node Structure
node {
597
Chapter 238. Set 235 (For SDE-II)
node leftChild,
node rightChild,
T data,
node neighbor
}
A
/ \
B C
/ \ \
D E F
Based on above tree,
Node: Neighbor
A: NULL
B: C
D: E
E: F
Told me write a program (It’s suppose to be recursive method)
Round 4:
1. Given a price rules of parking and start time and end time of parking. Calculate the
price (Below is the table of price rule) Come up with data structure you can store
these price rules PriceRule
Price Rules:
On Weekday On Weekend
Hours Price Hours Price
0–2 $5 0–2 $8
2–6 $10 2–6 $13
6 – 12 $15 6 – 12 $18
12 – 24 $20 12 – 24 $25
The interviewer asked me to come up with an architecture for a system which shows the
parking spaces available near customers’ location in a mobile app.
Round 5:
This round has been just behavioral questions,
598
Chapter 238. Set 235 (For SDE-II)
1. What would you do when the manager disagrees with your decision even though you
have a valid point?
2. What are the challenges you have faced in your career? How did you resolve it?
3. Explain the instance where you have contributed towards making the improvement in
your project or team.
4. What would you do when your peer disagrees with your decision? How would you
resolve the conflicts?
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-235-for-sde-ii/
599
Chapter 239
600
Chapter 239. Set 236 (Rounds 2 and 3)
7) what are the test cases to check whether your whatsapp is running properly or not ?
8) write a program to sort the numbers using singly linked list.
9) what will you do to check the response time of a webpage and also the derive the test
cases if the webpage doesn’t load completely.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-236-round-2-and-3/
601
Chapter 240
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-237-for-application-engineer/
602
Chapter 241
2. Tell YES or NO if two binary trees have the same numbers (could be of different
structures, non-unique elements)
3. Find the nth from frequent character in string (any character)
4. TPM guy: Design an elevator system (one lift, maybe more)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-238/
603
Chapter 242
Set 239
604
Chapter 242. Set 239
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-239/
605
Chapter 243
Amazon Interview Experience | Set 240 (1.5 Year Experienced for SDE-1) - GeeksforGeeks
I recently had interviews with Amazon. Here’s my interview experience
Coding round on Hacker rank (1 hour):
1. Find minimum number of coins that make a given value
Given a value V, if we want to make change for V cents, and we have infinite supply of each
of C = { C1, C2, .. , Cm} valued coins, what is the minimum number of coins to make the
change?
2. Suppose you have given two strings S1 and S2. Find out if S1 is substring of S2. If S1 is
present in S2 return starting index of S1 in S2 and if not present return -1.
3. https://www.geeksforgeeks.org/find-two-rectangles-overlap/
Face to Face Round 1 (Technical ~ 1 hour)
606
Chapter 243. Set 240 (1.5 Year Experienced for SDE-1)
2. Calculate how many paths exist from top left to bottom right corner of matrix with cost
= k. Number of paths with exactly k coins – GeeksforGeeks (For each question
they asked me to write the code and also tell all test cases.)
Face to Face Round 3 with Hiring Manager (Technical ~ 1hour)
607
Chapter 243. Set 240 (1.5 Year Experienced for SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-240-1-5-year-experienced-for-sde-1/
608
Chapter 244
Example:
1. Input: D Output: 21
2. Input: I Output: 12
3. Input: DD Output: 321
4. Input: II Output: 123
5. Input: DIDI Output: 21435
6. Input: IIDDD Output: 126543
7. Input: DDIDDIID Output: 321654798
609
Chapter 244. Set 241 (1.5 years experience)
2. Given a m*n matrix. m and n can be huge. We need to query the matrix for sum of
submatrices. Input will be the top-left and bottom-right co-ordinates. We need to return
the sum of submatrix in O(1) time.
Solution: Do column wise sum of the matrix and store it. Again, do the row wise sum and
store it.
Round – 4 (Q-city, Hyderabad) – Managerial
1. About projects, your contribution, your roles and responsibility, challenges faced etc.
2. Given m sorted arrays, merge it into one array.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-241-1-5-years-experience/
610
Chapter 245
1) http://www.geeksforgeeks.org/minimum-number-platforms-required-railwaybus-station/
2) http://www.geeksforgeeks.org/given-an-array-of-numbers-arrange-the-numbers-to-form-
the-biggest-number/
After one week, they called me to Hyderabad office for on-site interview. They have arranged
everything.
Every round started with interviewer introduction followed by my introduction.
End of every round, interviewer asked “Do you have any questions”?
611
Chapter 245. Set 242 (1 Year Experience)
2) He explained a situation like you have super market and items sold every day, blah blah…
finally the question becomes as follows
Given a file which contains one product id per line(millions of products) which are sold and
some product ids may repeat. We need to find how many items are unique in that file. (i.e
sold uniquely)
3) Cycle in a LL
4) How we can implement a queue with one pointer
5) Given a key , search the key in the LL, if exists swap the values of prev node and current
node. After I given solution then he asked me swap nodes NOT values.
6) Given a binary tree, construct a MIRROR of that tree.
So many behavioural questions around 10 -15 questions. some are
Give me an instance
2) Given a two nodes in a binary tree, check those are cousins or not. Cousins means both
have to present in same level but doesn’t have a common parent.
612
Chapter 245. Set 242 (1 Year Experience)
They wants within a single traversal of a tree we need to find. (2 traversal of a tree also not
allowed. I have done in two traversal � )
They given hints and finally we solved it.
3) Related to heaps
• Retrieve the rating for each product(ex:123456) which is present in that page (ex:
www.amazon.com/product/123456
• After finding ratings for every product(millions of products). Give an algorithm to
find top 10 rated products. Asked me to write production level code NOT pseudo
code.
• Then he extended if product ratings are same (it may occur for some product) then
we need to consider the product which has more number of comments
• Time complexity for above cases
Suggestions:
1) Need to cover (order is high to low priority): Trees, Heaps, sorting and searching,
LL, Stacks, Queues, strings, DP, Greedy, Divide and conquer, hash map and collisions,
recursion and back tracking, bit manipulation, basic graph algorithms, OOD, scalability
and memory units, any missing topics.
2) You sholud know the time complexity for STL data structures.
Ex: For hashing, we will say we can find a value in O(1) but if we are using C++ STL, map
was implemented with Balanced BST so it will take O(logn).
3) You MUST prepare some beheaviroual questions, atlest standard quesitons like Why
Amazon? Why do you want to live?
613
Chapter 245. Set 242 (1 Year Experience)
4) Practise on paper because you need to write on paper in all rounds of interview.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-242-1-year-experience/
614
Chapter 246
5. Given n non-negative integers representing an 2-D elevation map where the width of each
bar is 1, i need to compute how much water it is able to trap after raining.
615
Chapter 246. Set 243 (2.5 Years Experience)
616
Chapter 246. Set 243 (2.5 Years Experience)
TIPS
1. Practice to write the code using pen and paper.
2. Keep trying to solve the problem, they will definitely give you hints wherever you stuck
and you can capitalize on those hints to solve the problems.
3. Be honest with the interviewer.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-243-2-5-years-experience/
617
Chapter 247
618
Chapter 247. Set 244 (For SDE-1)
2. Given a large file, that cannot be loaded into the memory, with 2 fields, ItemId and its
description. Entry contains the list of all items sold on amazon.in. Track the most sold item
item at any instant.
I could not answer this question efficiently, I tried to explain him with MinHeap, he then
said to go ahead and code. I did, but there were some flaws. But he was satisfied with the
approach i took to solve the problem.
3. Design a network packet class.. Class designing for Request, Response and Timeout
Packets..
4. Some behavioral questions, like tell me a time when you helped a collegue, a time when
you were helped, what should you improve in yourself etc..
ROUND 5 F2F (Sr. Manager, 75 mins):
1. Asked about my current project in full detail, many questions why do we make this
product, whats the use, who uses it, for what etc..
2. Design a contact list, full production level working code was required for all methods.
How will we store the contacts, what classes will we use, how will we search.
So we should display all the matched contacts whenever we press some characters..
Suppose when we open contact list and it have many contacts like (….Saransh Santa Sarcastic
Secular Sharma Start …… )
So if we type S , the screen displays all contacts with “S” then when we type “Sa”, screen
must display Saransh Santa Sarcastic.
Suggestions:
1. DO NOT mug up the code. Understand it.
2. If stuck, ask interviewer for hints, they are very co-operative.
3. Prepare Data Structures(especially Arrays, Trees, DP, Linked List, Stack, Queues,
Strings, Heaps, Hashing for Amazon).
4. You should be flawless at explaining what you are currently doing and your past projects,
future is a reflection of past.
At last Thank you GeeksforGeeks for helping me through this.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-244-for-sde-1-hyderabad/
619
Chapter 248
Amazon Interview Experience | Set 245 (For 2.5 Years Experienced) - GeeksforGeeks
Round 1:
Q-1 Given an array os 0s and 1s, and another input m, I was supposed to tell the longest
continuous streak of 1s after flipping m 0s to 1s. E.g., Array is {1,1,0,0,1,1,1,0,1,1} m = 1
(which means I can flip ‘m’ one 0 to 1)
Answer: 6 (if we flip 0 at index 7, we get the longest continuous streak of 1s having length
6)
Q-2 Given N ropes of lengths L1, L2, L3, L4, …, LN. I had to join every rope to get a final
rope of length L1 + L2 + … + LN.
However, I can join only two ropes at a time and the cost of joining the two ropes is L1 +
L2. I was supposed to join ropes in such a way that the cost is minimum.
Round 2:
Q-3 Given a BST, I needed to serialize it and deserialize it. This essentially boiled down to
generating the “traversal” string and getting the BST back from the traversal.
Q-4 There are two linked lists. Both linked lists have a single-digit number in their nodes.
I needed to
treat this linked lists as a numbers and add them up and store the digits in a new linked
list.
E.g., head -> 5 -> 6 -> 7-> 9
head -> 2-> 1 -> 1
Resultant linked list: head-> 5 -> 8-> 9-> 0 (5679 + 211 = 5890)
Round 3: Hiring Manager round
Q-5 Project discussion in detail. Most challenging problem, how did you solve it, had any
disagreement with manager, how did you fix it etc.
Q-6 Given an array {2, 4, 6, 0, 1, 8, 1}, where each element represents the height of tower
located at its index. I was supposed to tell how much maximum water can accumulate in
this “valley” once it rains.
620
Chapter 248. Set 245 (For 2.5 Years Experienced)
Round 4:
Q-7 Given the encoding rule:
A -> 0
B -> 1
C -> 2
…
K -> 10
…
Z -> 25
I was supposed to get the number of original strings possible given an encoded input.
E.g., Given input 10, two possible original strings are possible BA and K, the answer is 2.
Q-8 Given two trees, find out if the second tree is a “subtree” of the first one.
E.g., Tree 1
A
/ \
B C
/ \ \
D E F
/
G
Tree 2:
B
/ \
D E
/
G
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-245-for-2-5-years/
621
Chapter 249
Round 3:
Given 2 design problems
1. I was asked to design a s/w for game shop in shopping mall.
Description: The game shop will distribute preloaded cards. That card needs to be used to
play any game. if the card has balance the cardholder will be allowed to play the game.
622
Chapter 249. Set 246 (For SDE 2)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-246-for-sde-2/
623
Chapter 250
624
Chapter 250. Set 247 (For SDE 1)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-247-for-sde-2/
625
Chapter 251
Amazon Interview Experience | Set 248 (4.8 Yrs Experience for SDE II) - GeeksforGeeks
1. WRITTEN ROUND
(a) Given lengths(costs) of ropes, find the total minimum cost of creating a single
rope. (cost of two ropes = length1 + length2)
(b) Find all the diagonal sums of a binary tree
2. F2F
(a) Design Movie tickets booking system
i. Class diagram with all relevant classes & associations
ii. find out all use cases
iii. describe a typical flow of events
iv. show how each use case is handled using your class diagram (selection of
seats, payment etc)
v. how would system be designed such that you can show the user complete
cinema hall with all seats in their respective locations.
vi. write a service for a front end controller which will let users to select multiple
seats according to their preference. Already booked seats & available seats
should be marked differently.
vii. how will the cost of a booking be determined (I used decorator pattern for
it)
3. F2F
(a) About projects I had worked on; current task; few questions on the current task
(b) Challenges faced when an urgent action was required from my side during the
project life cycle. What were the problems, how I tackled it, how I implemented
its solution
626
Chapter 251. Set 248 (4.8 Yrs Experience for SDE II)
(c) Architecture (design) of the project I had worked for the longest period of time.
(d) Other tasks I had done: Batch jobs & REST web services. Questions around
them
(e) Design a system having multiple jobs, interacting with each other such that (use
a DAG for this problem):
i. a job can run for very long periods (1-2 days)
ii. a node can fail/crash on which certain job is running
iii. system should be scalable
iv. amount of data getting transferred is huge
v. data in the system is very sensitive and needs security
vi. job/s can fail
4. F2F
(a) About projects, current task
(b) Design a system for a Building having various Access Points & Users having
multiple levels of access
i. Class diagram with all entities, relationships
ii. how will you achieve scalability? (handle the system when the number of
users accessing it is very high at the same time)
iii. write all the necessary services required
iv. how will you handle the scenario when a person misplaces his card
v. how will the scenario for visitors entering the building be handled?
5. Telephonic
(a) Tell about all your projects you have worked in your career till now and your role
and contribution in each.
(b) Reasons for switching earlier from previous company to current, project with in
the company and now to Amazon
(c) Toughest situations handled, your role, your solution, how feasible was it
(d) Process of tackling highest priority issues, solutions, implementation, approvals
and end result.
(e) Flow of events in a typical development and release cycle.
(f) Coding question (first design & then code on collabedit). Problem Statement:
You are given n number of mutually exclusive jobs with their schedules (time of
running) that need to be run on m number of nodes. Find minimum value of m
such that all jobs can run in their respective times. Optimize your solution.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-248-4-8-yrs-experience-for-sde-ii/
627
Chapter 252
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-249-telephonic-interview/
628
Chapter 253
Set 250
629
Chapter 253. Set 250
Ans -> 6 – for path 2,-5,-6,3,1 we need initial score of 6 so that when we land on 1, we have
a positive score of 1
After this everyone had a max of 3 interviews the same day, subject to qualification of each
round.
ROUND 3(Managerial):
Around 80% of the interview was about my current job and tiniest details about everything.
Design an automobile system -> two/three/four wheeler, petrol/diesel/gas, gear/non-gear
and classifications like this
How will you detect when a keyboard/mouse is attached to the computer? I said we will
have kind of listeners that listen to a port continuously and act accordingly. He insisted on
a solution without listeners. Had a good 5 mins discussion on this.
ROUND 4(Technical):
4.1 Linked list containing characters as values. Find if a linked list is palindrome.
4.2 Building Bridges Problem
4.3 Bottom View of binary tree
ROUND 5(Technical):
5.1 pow(a,b) needed to cover each and every case possible
5.2 LRU cache implementation
5.3 Given an array of numbers, form the largest number possible by concatenating all of
them. Needed to return a string.
After this, I was told that I can leave for the day, but next week will be called again for an
on-site-interview.
ROUND 6(Hiring Manager):
Again, 70-80 % of the time spent on my current work, minute details of each and everything
along with typical behavioural questions like hurdles faced, disagreement with manager,
conflicts and others..
Reverse a linked list again covering all possible scenarios
Some easy problem on binary tree (don’t remember exactly what)
After this I had to wait for almost a week for their call, where I was asked to appear for
another interview.
ROUND 7(Bar-Raiser):
Started with some behavioural questions like Why Amazon, why leave prev company along
with current job role details.
Longest Palindromic Substring in a string. The interviewer was satisfied with the first
solution that I suggested, asked me to code the same, and was convinced with the code too,
although I did make a small mistake which I realized later.
Initial intent was to ask two such questions, but I guess time restriction forced it to just
one.
Thanks a lot geeksforgeeks. The Amazon sets here did help a lot in the preparation.
All Practice Problems for Amazon !
630
Chapter 253. Set 250
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-250/
631
Chapter 254
632
Chapter 254. Set 252 (For SDET)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-252-for-sdet/
633
Chapter 255
1st round:
2 questions:
1. In a BST, replace value of each node with the sum of itself and everything greater than
itself.
2. There are two very large numbers, cant fit in any data type provided, so they are given
in a linked list (one digit per node). Sum the two numbers.
2nd Round:
2 questions:
1. Clone a linked list with random pointer.
2. In an integer array, find the window with maximum sum.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-253-for-sde1i/
634
Chapter 256
635
Chapter 256. Set 254 (Off-Campus for SDE1)
Face-to-face Interview 2 :
1. Given two nodes of a binary tree,check they are cousins or not. (Both Iterative and
recursive solution).
https://www.geeksforgeeks.org/check-two-nodes-cousins-binary-tree
2. Given an array with N elements (numbers from 0 to N-1). Find all duplicate elements.
I gave a solution with hashing, he asked me to do without extra space.
Then I gave solution with sorting the array, he asked me to do with only single traversal
and without extra space.
Face-to-face Interview 3 :
Started with brief introduction and some questions from my projects and CS fundamentals
(OS,Networks).
1.Given an input string and a dictionary of words, find out if the input string can be
segmented into a space-separated sequence of dictionary words. https://www.geeksforgeeks.
org/dynamic-programming-set-32-word-break-problem
Telephonic Interview :
The interviewer asked me to introduce myself, and after that he asked some behavioural
question like-
Have you got offer from any other company ?
Why are you intersted in joining AMAZON ?
1. Design a Elevator. How you store the input from users inside the elevator, outside the
elevator. How the elevator will take decision whether to go up,down or stop.
2. There is an event in the auditorium and Given capacity of the auditorium (NxM).
every group of person booked ticket and all the tickets are booked, Now you have to assign
seat number to all of them such that minimum number of group split.
We can solve this using this https://www.geeksforgeeks.org/dynamic-programming-subset-sum-problem.
Thanks a lot geeksforgeeks.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-254-off-campus-sde1/
636
Chapter 257
https://www.geeksforgeeks.org/trapping-rain-water/
2) Check whether two strings are anagram of each other.
https://www.geeksforgeeks.org/check-whether-two-strings-are-anagram-of-each-other/
Round 2 (Telephonic round):
1) Tell me about yourself.
2) Vertical Sum in a given Binary Tree
https://www.geeksforgeeks.org/vertical-sum-in-a-given-binary-tree/
3) Project Discussion
Round 3 (f2f onsite):
1) Tell me about yourself.
2) Sort a linked list of 0s, 1s and 2s
https://www.geeksforgeeks.org/sort-a-linked-list-of-0s-1s-or-2s/
637
Chapter 257. Set 255 (On-Campus)
638
Chapter 257. Set 255 (On-Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-255-on-campus/
639
Chapter 258
Amazon Interview Experience | Set 256 (Written Test for SDE1) - GeeksforGeeks
Recently i had an online test at hackerank platform for Amazon SDE1 position.
Following are the questions
1. Given an unsorted array, trim the array such that twice of minimum is greater than
maximum in the trimmed array. Elements should be removed either end of the array.
https://www.geeksforgeeks.org/remove-minimum-elements-either-side-2min-max/
2. Given a value V, if we want to make change for V cents, and we have infinite supply of
each of C = { C1, C2, .. , Cm} valued coins, what is the minimum number of coins to make
the change?
https://www.geeksforgeeks.org/find-minimum-number-of-coins-that-make-a-change/
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-256-written-test-for-sde1/
640
Chapter 259
641
Chapter 259. Set 257 (Off-Campus)
2nd part : Least distance of every empty cell to the nearest door. Lots of discussion was
done on both the parts of the problem.
I spend some time and finally came up with the working solution using Breadth first traver-
sal.
Q3) Find Excel column name from a given column number. https://www.geeksforgeeks.
org/find-excel-column-name-given-number/
This was the toughest round.
The interviewers had their flight to Bangalore and were getting late. So, next two rounds
were telephonic.
Round 3 (Telephonic) :
This round was taken by hiring manager.
Q1) Tell me about yourself. Your current company, your role and responsibilities. Reason
for leaving current company.
Q2) A 100 coin puzzle.
Q3) What happens after you write “a.out” and press enter. He wanted to know the func-
tionality performed by the OS after executable file is created of your code.
Q4) What happens when your code encounters NULL?
Q5) Garbage collector in Java. How is it different ?
Round 4 (Telephonic) :
Q1) Tell me about yourself. Your current company, your role and responsibilities.
Q2) Asked about the challenges faced in your current company. Any situation where you
were in disagreement with your manager. Any innovative or unique work performed in the
current company.
Q3) Connect nodes at the same level. https://www.geeksforgeeks.org/connect-nodes-at-same-level/
Proper working code was expected covering all edge cases. They shared the collabedit link.
Q4) What is Lock? Asked about semaphores, virtual memory, process scheduling.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-257-off-campus/
642
Chapter 260
643
Chapter 260. Set 258 (For SDE1)
Round 5:
1. Tell me about yourself
2. Projects and Internship
3. Given a tree where each node has an additional ptr called “next” ptr. Initially this next
ptr of every node is null. Write code such that each node’s next ptr should point to its next
bfs node.
4. Trending tab related question: Given a large stream of strings, return the top 10 most
frequently occurring string . (Hash map + min heap of size 10 is the solution.)
Round 6:
1. Tell me about yourself
2. Why do u like Database Mgt System (I had DB in my areas of interest)
3. Design the backend of a social networking application (Eg : linked in)
4. All OS related qns
5. Network qns
6. Oops concepts with real time examples.
7. General technical questions.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-258-for-sde1/
644
Chapter 261
645
Chapter 261. Set 258 (Off-Campus for SDE-1)
I did hear about this question before but never really saw the optimized solution so I gave a
O(m*m*n) solution. He asked me to optimize it, but I wasn’t able to do so, hence he asked
me to code the O(m*m*n) solution. I took a lot of time to code it as I wanted to handle
all the edge cases. Finally I coded it. He didn’t find any issues but he asked me to make it
better. And then I suggested using heaps to get the minimum of all the m arrays.
Lot of questions on why heap and why not BST. Asked me to prove it mathematically.
But he was satisfied once I gave the solution using heaps.
https://www.geeksforgeeks.org/merge-k-sorted-arrays/
Round 3 Bar Raiser : Telephonic
Discussion on my previous projects and asked some behavioral questions like why are you
leaving your current company, conflicts with your manager etc
Technical questions:
1) Find the maximum element in an array which is first increasing and then decreasing
https://www.geeksforgeeks.org/find-the-maximum-element-in-an-array-which-is-first-increasing-and-then-decreasin
2) Find the Pythagoras triplet in an array
Gave an O(n3) solution then made it O(n2logn). He asked me to optimise it even further.
Finally came up with O(n2) solution
https://www.geeksforgeeks.org/find-pythagorean-triplet-in-an-unsorted-array/
3) Given a very large binary number which cannot be stored in a variable, determine the
remainder of the decimal equivalent of the binary number when divided by 3
I had no clue about this question. He gave me a hint, with which I was able to solve it. But
later, he asked me to find the remainder for any number k. Again he gave a hint and I was
able to solve it.
Basically when we append a digit to a binary number, the previous binary number gets
doubled, hence the remainder also gets doubled.
If k = 3 then
5 = 1*3 + 2
2*5 = 2*3 + 2*2
Hence the remainder will be
(2*2 + 0)%3 = 1 for 1010
By keeping track of the remainder of the previous binary number, the current remainder
can be determined.
Round 4 Hiring Manager: Face to Face
Behavioral questions along with some questions about my previous projects.
646
Chapter 261. Set 258 (Off-Campus for SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-258-off-campus-sde-1/
647
Chapter 262
Ex : 3,4,7,1,2,9,8
Output : (3,8) and (4,7)
648
Chapter 262. Set 259 (1 Yr Experienced for SDE1)
Round 4 (Telephonic) :
Q1) Tell me about yourself. Your current company, your role and responsibilities. Reason
for leaving current company.
Q2) Maximum triangle path Sum : Starting from the top of a pyramid of numbers like
below, you can walk down going one step on the right or on the left, until you reach the
bottom row:
One of such walks is 55 -> 94 >- 30 -> 26. You can compute the total of the numbers you
have seen in such walk, in this case it’s 205.
Your problem is to find the maximum total among all possible paths from the top to the
bottom row of the triangle. In the little example above it’s 321.
Q3) Design your own Process Control Block(PCB).
Q4) Give me an example of a project that didn’t work out well?
Q5) What are some of the things that you and your supervisor have disagreed about?
Round 5 (Telephonic) :
Q1) Tell me about yourself. Your current company, your role and responsibilities.
Q2) Asked about the challenges faced in your current company. Did you ever have a boss
that you did not like or get along with?
Q3) Check for balanced parentheses in an expression. https://www.geeksforgeeks.org/
check-for-balanced-parentheses-in-an-expression/
I was asked to write code as well on collabedit site.
Q4) Move all zeroes to end of array. https://www.geeksforgeeks.org/move-zeroes-end-array/
649
Chapter 262. Set 259 (1 Yr Experienced for SDE1)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-259-1-yr-experienced-for-sde1/
650
Chapter 263
651
Chapter 263. Set 260 (For SDE2)
Note: In all they asked for production ready code. Please take care of all edge case.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-260-for-sde2/
652
Chapter 264
653
Chapter 264. Set 261 (For SDE1)
O(m*m*n) solution. He asked me to optimize it, but I wasn’t able to do so, hence he asked
me to code the O(m*m*n) solution. I took a lot of time to code it as I wanted to handle
all the edge cases. Finally I coded it. He didn’t find any issues but he asked me to make it
better. And then I suggested using heaps to get the minimum of all the m arrays.
Lot of questions on why heap and why not BST. Asked me to prove it mathematically.
But he was satisfied once I gave the solution using heaps.
https://www.geeksforgeeks.org/merge-k-sorted-arrays/
Round 3 Bar Raiser : Telephonic
Discussion on my previous projects and asked some behavioral questions like why are you
leaving your current company, conflicts with your manager etc
Technical questions:
1) Find the maximum element in an array which is first increasing and then decreasing
https://www.geeksforgeeks.org/find-the-maximum-element-in-an-array-which-is-first-increasing-and-then-decreasin
2) Find the Pythagoras triplet in an array
Gave an O(n3) solution then made it O(n2logn). He asked me to optimize it even further.
Finally came up with O(n2) solutionhttps://www.geeksforgeeks.org/find-pythagorean-triplet-in-an-unsorted-array/
3) Given a very large binary number which cannot be stored in a variable, determine the
remainder of the decimal equivalent of the binary number when divided by 3
I had no clue about this question. He gave me a hint, with which I was able to solve it. But
later, he asked me to find the remainder for any number k. Again he gave a hint and I was
able to solve it.
Basically when we append a digit to a binary number, the previous binary number gets
doubled, hence the remainder also gets doubled.
If k = 3 then
5 = 1*3 + 2
2*5 = 2*3 + 2*2
Hence the remainder will be
(2*2 + 0)%3 = 1 for 1010
By keeping track of the remainder of the previous binary number, the current remainder
can be determined.
Round 4 Hiring Manager: Face to Face
Behavioral questions along with some questions about my previous projects.
Then he gave me a technical question:
1) Given a number say ‘1234’, return the number in words i.e One thousand two hundred
and thirty four
654
Chapter 264. Set 261 (For SDE1)
Was able to cover all the scenarios. He was satisfied with my approach
Suggestions:
Think loud and be confident. It’s okay if you don’t know the answer at first. They mostly
see how you solve questions for which you don’t know the solution.
Thanks geeksforgeeks. You guys are doing an awesome job.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-261-sde1/
655
Chapter 265
656
Chapter 265. Set 262 (For SDE1)
F2F Round 3 :
1. Discussion on my projects and work in current company.
2. Given a general stack, design an advanced DS, such that getMin(),getMax() happens in
o(1). Many cross questions on this. about optimizations and all.
Then HR told me that all my interviews went well and they will call me for last round of
Interview. �
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-262-for-sde1/
657
Chapter 266
Set 262
Source
https://www.geeksforgeeks.org/amazon-interview-experience-262/
658
Chapter 267
1. https://www.geeksforgeeks.org/merge-two-sorted-arrays-o1-extra-space/
2. https://www.geeksforgeeks.org/check-for-balanced-parentheses-in-an-expression/
It was a phone interview of duration 1 hour. It was conducted on collabedit.com. This round
consisted 2 data structures and algorithms related questions. I was asked the following
questions:
1. https://www.geeksforgeeks.org/write-a-c-program-to-print-all-permutations-of-a-given-string/
2. https://www.geeksforgeeks.org/write-a-function-to-reverse-the-nodes-of-a-linked-list/
1. https://www.geeksforgeeks.org/square-root-of-an-integer/
2. https://www.geeksforgeeks.org/print-nodes-distance-k-given-node-binary-tree/
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-263-for-sdet/
659
Chapter 268
660
Chapter 268. Set 264 (Experienced for SDE1)
• If one of team member is not working or working very slow, how will you handle the
situation.
• When you have trained any colleague.
• Technology suggested by you in your team.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-264-experienced-for-sde1/
661
Chapter 269
INTERVIEW ROUND
There were 4 interview round. Each round took by different people and 2 questions were
asked in each. I am going to tell you about each round in detail.
ROUND 1
First question was ‘Tell me about yourself?’. I told her about projects like what I learnt
from it, what difficulties I faced, my hobbies and what I am looking for in future.
ROUND 2
Two Questions that were asked:
1. Given a complex weighted directed graph. Each weight represents the cost of transaction
662
Chapter 269. Set 265 (For Internship)
and each edge represents the transaction. The task was to minimize the graph and find out
the minimum cash flow.
I gave him one approach using hash map and coded the same.
2. Given an integer and decoding mechanism (like 1- A, 2-B……26-Z). The task was to find
out all the possible decoding of integer.
I applied dynamic programming approach and coded the same.
ROUND 3
He asked me to tell about my projects. I wrote three projects in my Resume. I discussed
them. Then he gave me some situation and asked how your project would solve this scenario.
1. Given an Amazon Store House where every products were stored like pens, balls
etc. Also the condition was that items can be sold in bundles like 2, 3, 5, 7 etc. The task
was that how I can sell those products if some order like 10 pens has come. It was asked to
solve it in an efficient manner.
I tried it using dynamic programming and solved it correctly. But interviewer replied
“No, you cannot apply dynamic programming here as you need to find the solution for all
the products and serve all the customer. Think of some other approach like using data
structure”.
Then I thought of another approach and that worked for me.
2. Given a BST and number K (which is one of those BST). The task was to find out the
closest value to K.
The solution was very easy. I did this with inorder traversal and picked the adjacent values
to K which has minimum difference with K. I coded the same.
ROUND 4
Here again, I was asked to tell about my projects. Some questions related to them were
also asked.
1. Given a room, where N number of person are present and some comparison
among them (like A>B, B>C, B<D etch). The task was to find out the greatest among
them.
I solved it first using dynamic programming approach but its’ time complexity was O(n2).
So I was asked to find out another approach. I tried it with two other approaches. The last
one was asked to code. I used hash map for the input.
Interviewer seems to me that he was satisfied with the approaches and code I gave. May be,
he didn’t ask the second question because of this.
MY SUGGESTION
I would suggest the following things to follow:
• Be confident and keep on trying to solve the question however it is tough. Be-
663
Chapter 269. Set 265 (For Internship)
cause they’re looking for your analytical and problem solving ability rather than solved
problem.
• Keep on telling about the approaches that are coming in your mind at the in-
stant. Interviewer may help you to let you know where you’re wrong (as happened in my
case).
• Keep on explaining while you’re finding the time complexity of the problem.
• Practice the coding (coding not pseudo code) on paper and dry run. Otherwise,
you may not be able to write it there.
I’ve been selected in Amazon with God grace.
Rohit Kesarwani
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-265-internship/
664
Chapter 270
665
Chapter 270. Set 265 (On-Campus Internship)
Explanation: We can read the number n as 1, 2, and 1. The string formed will be ABA
(1=A, 2=B). We can also read the number n as 12 and 1. The string formed will be LA
(12=L, 1=A). We can also read the number n as 1 and 21. The string formed will be AU
(1=A, 21=U). So we can form maximum 3 distinct strings out of number 121 using the
given mapping.
I gave a recursive solution and the interviewer was satisfied with my solution. So he asked
me to code my solution on a paper. I coded the solution and then he checked my code.
Once he was satisfied, we moved on to the next problem.
Q2. https://www.geeksforgeeks.org/remove-bst-keys-outside-the-given-range/
After a while the shortlist was announced. 10 students got shortlisted for the next round. I
too got shortlisted for the next round.
Round 3: Final Interview
This was the final interview of the process. The inteviewer first asked me to introduce myself
and then he asked me about one of my project. He then asked me several questions, which
are as follows:
Q1. What is a binary tree? What are different types of traversals in a BT? What is the
difference between these traversals? Which of the traversal is based on BFS and which is
based on DFS?
I answered the questions appropriately. He was satisfied with my answers.
Q2. https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/
Once i gave him the solution, he asked me to code it on a paper. He checked my solution
manually with some test cases. Once he was satisfied, we moved on to the next question.
Q3. What is a max heap? What is a min heap? What are some real life applications of
heaps?
Q4. How to insert in a heap? What is the time complexity?
Q5. How to delete a min element from a min heap? What is the time complexity?
Q6. Given an array of n numbers, how can i build a min heap from the array. What is the
time complexity?
I answered him appropriately. I told him that we can solve the above problem in O(n) time
complexity. He then asked me to prove that the complexity is O(n). I proved it with an
example array. He was satisfied with my answer.
Q7. There is a constant flow of numbers coming in from some infinite list of numbers out of
which you need to maintain a data structure as to return the top 100 numbers at any given
point of time. Assume all the numbers are integer numbers only.
Sol: I gave him a solution using min-heap. We can create a min heap of 100 elements.
The first 100 elements is easy to handle. Let say we get the 101th element in the list. If
this number is less than the root of the binary heap then we need not do anything. If this
number is greater then the root of the binary heap then we need to replace the root element
with this element and call percolate-down procedure on the root of the binary heap.
My interviewer concluded my interview with this question.
666
Chapter 270. Set 265 (On-Campus Internship)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-265-on-campus-internship/
667
Chapter 271
668
Chapter 271. Set 266 (Off-Campus for SDE1)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-266-off-campus/
669
Chapter 272
670
Chapter 272. Set 266 (SDE 2)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-266-sde-2/
671
Chapter 273
672
Chapter 273. Set 267 (8 Months Experienced)
that have you done it before and i said no then he asked me to code it. I had no idea of the
code as i haven’t done it before. i struglled to write the correct code 2-3 times and at last i
wrote the correct code.
Then he said to me i am done with the interview, Do you have any question for me and i
asked two question.
Production ready code was required.
F2F Round2 :
Again Started with a brief introduction and some project discussion.
Q1 : A question similar to LCA(Least Common Ancesstor) of Tree and i gave the answer
immediately as i have understood the question and didn’t ask any further clarification.
Q2 : Given some resources in the form of linked list you have to canceled out all the resources
whose sum up to 0(Zero) and return the remaining list.
I gave the solution immediately but couldn’t handle some of the corner test cases then he
asked me to modify the code accordingly.
Then he asked me to write all the test cases for it and i did.
For eg; given the resources like this :
case 1 : 6 -6 8 4 -12 9 8 -8 It should return 9 as all others get canceled.
In the above example lists which gets canceled :
6 -6
8 4 -12
8 -8
o/p : 9
case 2 : 4 6 8 -9 10 -9
o/p : 4 6
case 3 : 4 6 -10 8 9 10 -19 10 -18 20 25
O/P : 20 25
F2F Round3 :
Started with a formal introduction and BTW he was the same guy who took my telephonic
interview.
Q1) He asked me subset sum problem i.e; Given an array find the maximum sum contiguous
subarray.
I gave O(n) solution for finding the maximum sum immediately after he asked the question
as i knew the solution.
Then he asked me to trace the code for some test cases and it passed.Then he asked me
to find the staring and end index of the subarray and I modified the code and initially got
wrong but after some modification I got the code right.
Q2) Sum of numbers represented by two linked list .
And i gave the answer immediately after he finished the question. But i gave the soln for
adding two linked list numbers starting from beginning but he told me add the numbers as
we do in normal addition.
And i gave that solution to by reversing the linked list and then adding the numbers and
finally reversed the resultent list.
After 2-3 days i got a call from Amazon that i have cleared the rounds and they asked me
to come for Hirring Manager Round.
One of the interviewer gave me feedback that he mugged the answer as i gave the answer
immediately after the interviewer asked the question as i came to know later which was
673
Chapter 273. Set 267 (8 Months Experienced)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-267-8-months-experienced/
674
Chapter 274
675
Chapter 274. Set 268 (Experienced)
https://www.geeksforgeeks.org/trapping-rain-water/
c. Given two strings print all possible permutations of two strings such that the order of
characters are maintained.
I gave a topological sort solution and then a recursive solution.
Round 4:Hiring Manager Round
a.A lot of behavioural questions like weakness,strengths,why leaving previous organization.
b.Detailed description of projects
c.Given an array,generate all valid ip address from the array.
A lot of discussion on this question and finally I gave a hashmap solution to this ques-
tion.Time complexity:O(n)
Round 5: Bar Raiser
a. A lot of behavioural questions,why amazon etc etc
b. Find the longest palindromic substring in a string.
I told him we can reverse the string and find the LCS for both strings.
Full working code was required at each round and time complexity was discussed in detail
for questions. Thanks a lot geeksforgeeks.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-268-experienced/
676
Chapter 275
Amazon Interview Experience | Set 269 (1 year experienced for SDE-1) - GeeksforGeeks
Online Round: 2 Programming questions for 2 Hours
1. Convert set of strings in number as given on phone keypad. String will contain only
lower case characters. Print these strings with numbers in descending order of numbers,
if numbers are same then lexicographical order of strings.
Input: amazon, rat,pat
Output: 262966 amazon
728 pat
728 rat
2. In a M*N maze you can move in any direction(left,right,up,down). There are bomb
on some positions. Starting from (0,0) find the number of moves require to exit from
the maze. Exit point is (m-1,n-1). If its not possible then return -1. Similar to
Minesweeper Game.
677
Chapter 275. Set 269 (1 year experienced for SDE-1)
1. Correct a deformed BST. All kind of approaches and proper reasoning for each. Then
asked to write the code.
2. Array question. similar to https://www.geeksforgeeks.org/given-a-string-find-its-first-non-repeating-character/
.
3. https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/.
All the interviewers were very helpful. In all rounds for every question they were looking
for what kind of approach you are going to use and proper reasoning for the same. Not just
coding , neat and efficient coding was required because for each question at the end you
have to code and they expect you not to miss edge cases.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-269-1-year-experienced-for-sde-1/
678
Chapter 276
eg. n = 3
matrix: 1 2 3
4 5 6
7 8 9
k = 4, output: 6
k = 6, output: 8
Round 2: (F2F)
1. Given a boolean matrix find the row with maximum number of 1s
2. Given a pointer to a node of a tree, print the inorder successor. Assume that you have a
function getParent(node) which returns the parent of the node
3. Given a array find the configuration where we will get max sum of i*array[i]
eg: 8312 = 8*0 + 3*1 + 1*2 + 2*3 = 11
3128 = 3*0 + 1*1 + 2*2 + 8*3 = 29
1283 = 1*0 + 2*1 + 8*2 + 3*3 = 27
2831 = 2*0 + 8*1 + 3*2 + 1*1 = 15
max value here is 29 when array is rotated by 1
expected time complexity O(n)
hint: see what goes out and what comes in when the array is rotated. You dont need to
rotate the array
679
Chapter 276. Set 272 (On-Campus)
680
Chapter 276. Set 272 (On-Campus)
Thanks Geeksforgeeks.
Recruiter at amazon are very friendly. Interact with the interviewer if you get stuck. Try
to come up to different approach to solve the same problem. Their main focus remains on
how you see a problem and try to solve the problem. Don’t jump to code it as soon as you
are given the problem, first discuss it then go for coding if asked. Be confident and don’t
give up if you can’t get the perfect solution.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-272-on-campus/
681
Chapter 277
682
Chapter 277. Set 273 (On-Campus)
1. You are given an array of elements, find out if the array represents Pre-order traversal of
a BST.
I thought on it for few seconds and gave her n^2 logic. Before she asked me to optimize it,
I told her that I can try to optimize it.
Then after thinking about it for few minutes, I told her my O(n) logic.
After listening to my approach, she asked me to code it. I wrote the code without any
error at one go. She asked me the time complexity and space complexity of my code after
checking if its error free or not.
After this, the interviewer asked me theoretical questions on OS such as what is critical
section, mutex, semaphore, virtual memory, page fault, ways of preventing deadlock, etc.
Then she made a simple table and asked me to write SQL query for it which was very easy.
She asked me what is indexing in DBMS, difference between its types and if the query I
wrote is case sensitive or not.
Next the interviewer asked me if I know clone a linked list problem or not.
I said, yes. So the interviewer changed the question.
2. Given an array with both negative and positive numbers, find the maximum sum con-
tiguous sub-array.
I told the interviewer my approach (modification of Kadane’s algorithm). And she asked
me to write the code. I wrote the code without any errors.
683
Chapter 277. Set 273 (On-Campus)
3. You are in a forest and there are many paths. You need to get out of the forest. Which
path do you choose?
It was a problem of finding the minimum distance between source node and destination
node in a graph.
I told him my approach and then he asked me to explain dijkstra’s algorithm. Then the in-
terviewer asked me the difference between dijkstra’s algorithm and floyd-warshall algorithm.
Then he asked me about prim’s algorithm and kruskal’s algorithm.
Then he gave me another interesting problem.
4. For each node of a binary tree, you are given the node id and sum of the ids of its children.
Find the node id of the root.
After few minutes I came up with a wrong approach. As soon as I told the interviewer about
it, I understood I was wrong. Then he told me to focus on the sum of the ids. Then within
a minute I told him another approach. He asked me why this works, I explained him and
he was satisfied.
After that the interviewer asked me if I had any questions for him. At last, he again asked
me about one of my project in which I used Alexa.
Keeping calm will help you come up with a correct solution faster, ask questions to inter-
viewers if you have any doubt, they are very friendly. Practice questions from geeksforgeeks.
It helped me a lot. Thank you geeks.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-273-on-campus/
684
Chapter 278
Round 2: (F2F)
Round 3 : (F2F)
685
Chapter 278. Set 274 ( On-Campus)
Round 3:(F2F)
686
Chapter 278. Set 274 ( On-Campus)
Recruiter at amazon are very friendly. For each question working code was expected and
time and space complexity was asked.
Interact with the interviewer if you get stuck. Try to come up to different approach to solve
the same problem. Their main focus remains on how you see a problem and try to solve the
problem. Dont jump to code it as soon as you are given the problem, first discuss it then
go for coding if asked.
Be confident and do not give up if you cant get the perfect solution!!
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-274-on-campus/
687
Chapter 279
There were about 80 candidates and the time allotted for this round is 1 hour. I was able
to write all the 3 codes correctly in just 20 min and was the first candidate to move onto
the second round.
Round 2 : Problem Solving (F2F)
688
Chapter 279. Set 275 ( Off-Campus SDE-I Experienced)
• Behavioral Questions :
– Tell me about your Current Projects in Samsung.
– What are your responsibilites as a Project Lead ?
– Why do you want to join Amazon when you are doing so good in Samsung ?
– At last a 15 min discussion about the most difficult problem I ever faced and how
I tackled it with my coding skills and knowledge.
The interviewer was highly impressed with my coding skills and shook hands with a sense
of approval.
Round 4 : Hiring Manager (F2F)
The Hiring Manager introduced himself and told me that I’ve been doing really great till
now. Then he grinned at me and said “ Lets hope you don’t mess it up in this round “ .
(1) Which Sorting Algorithm is the fastest and why would you prefer it over others ?
While telling the answer, I said in between “ If there would have been millions of numbers……
“ and he caught that specific word of mine “millions” and hence the next 2 questions found
the way on their own.
• In a city with millions of people, I want to sort them on the basis of their age.
Which Sorting Algorithm would you use and why ?There’s a Galaxy with Billions
of Stars and distance of each star from the Sun is given . I want the closest 1 mil-
lion stars from the Sun. Which Data Structure would you use and what would be
the complexity ? (It is a variation of Finding K Smallest Elements in an Array)-
https://www.geeksforgeeks.org/k-largestor-smallest-elements-in-an-array/
• Find distance between two given keys of a Binary Tree https://www.geeksforgeeks.org/find-
distance-two-given-nodes/
He scrutinized the entire code for any possible errors and found it perfect.
Then he stood up and shook my hands with a broad smile and said “ Well Done Man ! ”
and left.
Round 5 : Bar Raiser (F2F)
689
Chapter 279. Set 275 ( Off-Campus SDE-I Experienced)
Only this question was asked in this round and the discussion went on for about 45 minutes.
All credit goes to https://www.geeksforgeeks.org/ team for providing such an inspirational
and a brilliant platform for coders. Keep it up guys, Way to go !
Suggestion for other candidates interviewing at Amazon :
• Try to write Neat and Clean codes without any cutting or hassle, taking care of all
the boundary cases.
• Be very precise and explicit in your answers. Keep Coding and All the Best !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-275-offcampus-sde-i-experienced/
690
Chapter 280
• Round 2(F2F) 1. Given two arrays containing numbers find all possible orderings
(a, b) such that a*b=P(given product) where a belongs to array 1 and b belongs to
array b.
Approach: Store all elements from shorter array in hash and traverse the other and
find if (P/b) is present in the hash. If present print the ordering.
1. Given a circular road having gas stations at varying distances on the road. The cost to
move from one station to another is given. You can refuel at each stations with all the
present at the station as the tank capacity is infinite. Find if its possible to traverse
the complete road and if yes then find the starting position to finish the route.
Approach: Start from beginning and start traversing the road. If fuel finishes at any
point then move the start index backwards and add its gas to the tank. If its still -ve
then keep doing it until you have enough to move forward.
• Round 3(F2F)
691
Chapter 280. Set 276 ( On-Campus SDE-I)
1. Given a N*M matrix, print all squares/rectangles of all possible sizes(all 1*1,
then all 1*2…. 2*1… )
Approach: Brute Force
2. Serialize a Binary Tree
Approach:
(a) Store any two traversals. But it takes a lot of space.
(b) Store all the nodes and store for each node the information if it has left &
right sub-tree or not in a Boolean array.
• Round 4(F2F) 1. Function to find optimal selection of packages from amazon ware-
house. Packages contain varying units of a product for eg: one can have 5 units of
iphones another can have 3 and so on. Each package is present infinitely ie. take one
then there are still infinite left. You can break into a package, you have to take it as
a whole. Also, smaller size packages should be used first. Lot of modifications.
Approach: Suggested subset sum dp solution. Couldn’t handle infinite case properly.
2. Add one to a given number represented using a linked list where MSB was at tail
and LSB at head.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-276-on-campus-sde-i/
692
Chapter 281
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-277-for-internship/
693
Chapter 282
694
Chapter 282. Set 278 (On-Campus)
Round 4:
Hiring Manager round
This round is different from other rounds.
For me, its 1 hour 45 minutes.
But some of my friends have different timings like 15 to 20 minutes and 45 to 60 minutes.
In this round, there are two HRs for me.
They gave their Self intro with awesome communication. Really awesome.
They ask,
Self Intro
Project Explanation
Testing for my Project
Testing for the project and scenario given by us – I wrote 94 test cases (when I get ready
for 95th test case , she asked me to stop and said, “its enough..” ) .
Troubleshooting for the test cases provided by me to my Project – I wrote 60 test cases.
Troubleshooting for the test cases provided by me to the project and scenario given by us.
Then they ask Database queries and questions.
Programming question based on the File Management System – For this also, I prefer C
Data Structures and Python – The expect more number of solutions as well as the best
solution.
Communication was checked.
Culture fit questions.
Then, question session for me to them.
At last, they said, “Thank you Sathish , we done the interview. We will give the results to
your Placement officer.”
Thank you GeeksForGeeks :
Because, I prefer GeeksforGeeks for my programming preparations. You played a major
role in my placement.
Practice Amazon Interview Questions.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-278-on-campus/
695
Chapter 283
696
Chapter 283. Set 279 (On-Campus for Internship)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-279-on-campus-for-internship/
697
Chapter 284
F2F – 1
After clearing the written round I went for first F2F round.
1. There is one class which has private array list and this array list is initialized in
constructor of this class.
We have one public method getItem(int i) { ” return ith item of array list” }, We need to
know the size of array list. We can only call getItem method.
https://ideone.com/VaE0QL
Please check the above code for more details.
2. Search an element in a BST.
3. Given a set of time intervals in any order, Print all the pair of overlapping intervals .
4. My college project was on RTOS (Real Time OS) and interviewer also did the same
project when he was in college , so we had lot of discussion on project.
He was very impressed.
F2F-2
Here is F2F round 2 where I was not able to give optimized approach for the first problem.
1. Given a string and he asked me to find Longest Repeated Substring in the given string.
698
Chapter 284. Set 280 (Off-Campus)
2. Given a mXn matrix with no obstacle and we can move in right or down direction. Count
the no of paths to reach from top left cell to bottom right.
I gave recursive solution with 2^n complexity and then optimized the solution using memo-
ization.
3. Create sorted list of all unique partitions of given number 5 = { {4, 1}, {3, 2}, {3, 1, 1}
…. }
https://www.geeksforgeeks.org/generate-unique-partitions-of-an-integer/
This round didn’t go well and I was praying L Finally HR came and said you haven’t
performed well in this round so you will have another technical round and I was like “ok no
problem”.
F2F – 3
Finally last round of the day and I knew I have to perform well otherwise I have no chance.
1. You are given a dictionary and a string. You need to check the string is valid (exist in
given dictionary) or not, if its not valid then perform one of the three operation (Insert ,
remove , replace) on string and get a valid string. We need to find another string which
has One edit distance with this string.
Interviewer asked me about the data structure used to implement the Dictio-
nary. I suggested Trie for dictionary. After some discussion he asked me to write
code for insert in Trie and for the above problem.https://www.geeksforgeeks.org/
dynamic-programming-set-5-edit-distance/
2. How to implement Trie. Space optimized version.
This was part of 1st problem and we had discussion on space of a trie when we have 500-600
characters in some language. I suggested HashMap instead of using static array in Trie.
And then he asked me to write structure and Insert method.
3. Max sum tree . every node has its value plus maximum of left and right sub tree sum.
Expected time complexity O(N).
After this round HR told me to leave for the day and I will have one more technical and
one Hiring manager round.
I was happy that I completed all the round.
4. Find maximum sum rectangle in given matrix.
699
Chapter 284. Set 280 (Off-Campus)
Guys prepare hard for behavioural questions, these questions are asked to know the person.
Then 2 easy programming questions but again the measuring part was code and the way
we explain our solution.
1. Check a string is palindrome or not.
2. Count no of words in a string.
He asked me to write test case for both the problem.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-280-on-campus-for-internship/
700
Chapter 285
1. http://quiz.geeksforgeeks.org/lexicographically-minimum-string-rotation/
2. It was an easy string question similar to finding that the parenthesis are balanced or
not . Instead of the parenthesis , a and b were to be checked for , For eg )
ababab is balanced ;Its a good string
abbbaa is a bad string .
1. Set the rows and columns of a matrix equal to zero if an element in that row or column
is zero (The elements could be positive or negative too ). I told him the solution using
O(n) space . He then asked me to do it without the auxillary space and I told him
701
Chapter 285. Set 282 (On-Campus)
that it was not possible . (A solution without space could be given if all the elements
were either non-negative or non-positive )
2. Merge k sorted linked lists . I discussed the approach using priority queue . Then he
proposed another method of merging two lists into one and then merging it with the
next . I explained him the complexities of both the approaches and then wrote the
code for priority queue approach . He was impressed.
I would like to thank GeeksforGeeks for providing a huge set of problems for practicing
for interviews. The internship archives were extremely helpful . Also I practiced on https:
//practice.geeksforgeeks.org/ and interviewbit regularly in the summer break.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-282-on-campus/
702
Chapter 286
703
Chapter 286. Set 283 (On-Campus)
First i gave bruteforce approach and after that I gave a segment Tree solution to that with
time and space complexity .
He then asked what if we have to update an element and then followed by updating a range
.
After that he asked what if we delete an element . How do you modify your solution to
cope-up with that .
I suggested him to update the element with INT_MAX and maintain a mapping array .
After that he asked what if we add an element in the array ? .
I suggested him to reconstruct segment tree based on that . He suggested to construct it
like a binary root instead of array representation and store the range . There can be some
re-usable subtrees . How can i found those subtrees and how to use them and what will be
the time complexities.
Lastly i was told to code range minmium query with node having following properties
(min,start,end,node* left,node* end ) ;
He got impressed .:)
Round 3
————–
It also consist of only a single problem .
Problem : Given set of coordinates find top k elements whose distance from origin in
maximum .
I gave naive approaches and heap approach . Later he asked me to think more then i come
up with Quick-Sort Partition function approach .
He asked me to code it .
Round 4
—————
It was easiest of all so far .
It consist of problem : Given 2 linked list subtract them and store the result in bigger one
and return that .
Basically he wants us to cover all corner cases for this .
After that a discussion on projects took place.
Thanks Geeks For geeks for huge programming problems database . Doing a great Job � .
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-283-on-campus/
704
Chapter 287
705
Chapter 287. Set 285 (On-Campus for JD-SDE)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-284-on-campus/
706
Chapter 288
707
Chapter 288. Set 286 (On-Campus)
The MCQs were pretty easy to solve if the concepts are clear. The code was manually
verified by team and then students were shortlisted based on the quality of code and overall
score.
Round 2 (F2F) Duration: 60 minutes
The interviewer was in a hurry I felt and he asked me some basic questions like “tell me
about yourself?” and then we discussed about my internship and it went on for 10 minutes
before he came up with a question.
1. Design the shuffle button of a music player such that it maintains random property and
make sure that it plays all the songs uniquely in a cycle (i.e, no song should repeat itself
unless all other songs in a particular cycle are played)
I initially gave him an O(nlogn) approach. He wanted me to optimize it and after some
pen and paper work I came up with an O(n) approach and the interviewer seemed to be
satisfied.
Round 3 (F2F) Duration: 70-80 minutes
The interviewer was very friendly and made me comfortable by offering some snacks and
water. Later he asked me to give my best shot and to not fool him if I had already heard
of the problems he was going to ask. He asked me to tell few lines about myself and then
discussed about my internship for 5 minutes and then fired few questions.
1. Traffic Car Problem. Given n people and n+1 parking slots. Each person has a car and
a parking slot allocated. One night they all go to a party and get drunk. They end up
parking their cars randomly. What’s the best way to go back to the initial configuration
(one where every car is in the right allocated slot). n+1th parking slot can be used to swap
the cars.
I told the interviewer that this question was asked to one of my friends and that I discussed
it with him. He seemed impressed with my honesty. He then moved on to ask the next
question.
2. A variation of stock buy sell to maximize profits problem : https://www.geeksforgeeks.
org/stock-buy-sell/
3. Trapping Rain Water Problem : https://www.geeksforgeeks.org/trapping-rain-water/
Tips: Keep the interviewer involved in the discussion. Give him the approach and if you
are not thinking in the right direction, they are always there to guide you. Don’t jump to
the code as soon as you are given the problem.
I coded the last two problems after explaining him the logic behind it and the interviewer
seemed to be satisfied.
Round 4 (F2F) Duration: Around 90 minutes
Initially there was only one person who was interviewing me but then he was joined by
another person and it looked that I needed both of their approval to move into the next
round.
1. We started off with discussing my previous internships. He was very curious to know about
708
Chapter 288. Set 286 (On-Campus)
what were my key deliverables as an Intern and also seemed to learn from my experience at
those firms.
2. Count ways to reach nth stair : https://www.geeksforgeeks.org/count-ways-reach-nth-stair/
I first explained him how the result can be derived and then after he was satisfied with the
logic, gave him a recursive approach, followed by the memorization approach and then the
iterative Dynamic Programming approach.
3. Tree Isomorphism Problem : https://www.geeksforgeeks.org/tree-isomorphism-problem/
Logic was given and then I coded it. He still didn’t seemed to be satisfied and asked me to
walk him through my code for an example tree and draw the recursion tree for the same.
4. Dynamic Programming (Longest Arithmetic Progression) : https://www.geeksforgeeks.
org/length-of-the-longest-arithmatic-progression-in-a-sorted-array/
5. He asked me to design a student database efficiently.
Raw thinking was what he wanted I felt.
6. Few DBMS related query questions that were simple to answer.
Round 5 (F2F) Duration : 100-120 minutes
The interviewer was very friendly at the beginning. He became little strict as the interview
went on and in the end he again turned back to the amicable mood he started with �
1. We started off with discussing my internships in detail. This went on for about 30 minutes
until he was satisfied with that fact that I had put in lot of effort in making it a successful
project.
2. Stock buy sell problem which was asked in the second round. I told him that this was
asked to me in the earlier rounds and he seemed to be impressed with my honesty. I guess
I got some loyalty marks there.
3. Connect the nodes of the binary tree in the same vertical level by using the next pointer.
The tree could have nodes with at most two parent nodes.
Approach was given and he didn’t seemed to be fully satisfied with my code at first, but
then after some optimizations he said it seems to be fine now.
4. Few question on Paging, Collision Resolving techniques, Page replacement algorithms.
Probably the interviewer wanted to make sure that the new hire is well familiar with other
subjects other than DSA. He seemed to be satisfied with the answers.
5. Why Amazon?
The standard question that everyone is asked in the end of the last round.
Thanks GeeksforGeeks.
Tips: Try to be calm and give the interview. The interviewers are very well experienced
and they not only test your technical skills but also read your expressions (on how well
you respond to what they ask). Sometimes luck might not be on your side, so do not get
disappointed even if you are rejected. Keep practicing and indeed you will crack some good
firm soon �
All Practice Problems for Amazon !
709
Chapter 288. Set 286 (On-Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-285-on-campus/
710
Chapter 289
711
Chapter 289. Set 287 (On-Campus)
712
Chapter 289. Set 287 (On-Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-287-on-campus/
713
Chapter 290
714
Chapter 290. Set 288 (On-Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-288-on-campus/
715
Chapter 291
716
Chapter 291. Set 289 (On-Campus for Internship)
Then he gave me a chance to ask him questions if I had. I asked him, “How many hours
do you code in a day?” He replied, “Sometimes I don’t write code at all, sometimes it is
12-16 hours.” He also mentioned that his wife doesn’t like him. I told him, you should have
married a CS girl. He was laughing. I asked some other questions and it was really an
awesome conversation.
3. 3rd round was HR round. The interviewer started talking about the life and culture
at amazon.
Then he asked me the problem of finding whether two nodes in a Binary tree
are cousins or not. I was not able to solve it at first. I was nervous. I wrote the code but
again it was wrong, he told me you’ll get 2 more minutes for 5 times. But he gave more
than 10 minutes to solve it. Actually he was trying to confuse me.
2nd question was a math question, it was easy and then he told me to implement insert
method
of MaxHeap. I told him that I can’t. I can use MaxHeap but I’ve never implemented
MaxHeap. He said, “Then implement it now.” I did and said, “Have you ever implemented
MaxHeap insert method in O(1) time ?” He just stared at me and then I said, “I don’t like
remembering algorithms that I don’t even understand. And I never needed this algorithm
as well”.
Later I apologized for the arrogance that I showed. He asked me lot of questions like why
do you want to work at amazon ? Then he gave me a chance to ask him quetions. I asked
the same question,
“How long do you code ?” He said, “I don’t write codes at all.” I said, “Why ?” He said,
“Because I’m the HR manager” I said, “I thought that there will be one more round and
that’ll be the HR round.
And I heard that the HR manager likes to ask mathematical questions”. He laughed and
said, “I asked you one.”
And one advice that I can give you is that You don’t need to know thousands of algorithms.
Apply your brain to develop them because they’ll give you sufficient time to do that. Re-
membering algorithms is a bad habit. And be confident and proud of what you already
know. Thanks geeksforgeeks for giving me such an unexpected happiness.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-289-on-campus-for-internship/
717
Chapter 292
718
Chapter 292. Set 290 (On-Campus for Internship)
Few advises – First, be cool and don’t be nervous because interviewer wants you to be
interactive and confident. Think out loud and keep discussing with interviewer about any
of your queries. Lastly, just memorising algorithms won’t do any good. One has to learn
the art of developing logic of a problem.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-290-on-campus-for-internship/
719
Chapter 293
F2F 1(Technical):
He asked me about my Summer Internship Project at Microsoft India Development Centre,
Hyderabad and asked me about several technologies involved in it and why I had used
certain things.
Then he moved on to two technical questions.
1. Given a sorted and pivoted array, find an element given to you.
I had given him a O(logn) solution with pivot finding and then doing binary search in
either halves. But it was a O(logn) + O(logn), so he asked me to modify it to a one
O(logn) question. After giving him the solution, he asked me to write production level code
considering all corner test cases.
2. Given a BST which consists of marks of students in a class. It is found that all even
ranked students have cheated,so we reduce k marks from their score. Modify the BST to
720
Chapter 293. Set 291 (On-Campus for SDE1)
make the change of marks without considering that after this operation, the BST might not
remain a BST anymore.
I gave him a modified inorder traversal so that elements are sorted and solved it using a
counter variable. He asked me to modify it to using neither a static counter variable nor
a pointer passed to the recursive calls. For both questions, he also asked me the time and
space complexity.
F2F 2(Technical):
He asked a very brief idea about my Summer Internship again. Then he asked me 2 questions
again.
1.Given a k sized window in an array,find max element in each window.
https://www.geeksforgeeks.org/maximum-of-all-subarrays-of-size-k/
I discussed a lot with him as to which data structure could be used and finally came up
with a Queue solution. I was asked to code it again considering all the corner cases.
2.Implement a queue using stacks with the operations (Enqueue,Dequeue,IsEmpty,Size).
While I was telling him the solution,he even asked me whether I would prefer Arrays or
Linked List implementation when i make a normal queue.
(Space and time complexity for both)
F2F 3(Technical):
He also asked me a brief introduction to my Summer Internship Project.
He began with the pros of cons or arrays and linked lists. Then a question on arrays:
1. Given an array with all even elements present even number of times except one which is
present odd number of times. Find that element.
I started with XOR solution, but he told me the OS doesn’t support XOR.So,I gave him a
HashMap solution. He went on asking me to optimize further. So at the end I had a space
complexity of O(k) where k= number of unique elements.
Asked me the Space and Time complexity of the most optimized solution.
2. Given four types of array
a)Increasing(1,2,3,4)
b)Decreasing(4,3,2,1)
c)Increasing-decreasing(1,2,3,4,7,6,5)
d)Decreasing-increasing(7,6,5,1,2,3,4)
Find the type of array in O(1) and then find the maximum element in the array.
Except case c, max element is O(1). For c, I gave binary search solution. he asked me to
write the code considering the corner cases.
F2F 4(Bar raiser):
He asked me what my favorite subject was. I told DS,so he asked me from DS.
721
Chapter 293. Set 291 (On-Campus for SDE1)
1. Write a class of circular queue using array implementation with Enqueue and Dequeue
member functions.
2. Given a binary matrix( filled with 0 and 1 only) where 0 depicts water and 1 depicts land.
We can traverse either up or down or left or right.Given a source and destination,find if we
can reach the destination.
He then modified it to finding the path followed and then the minimum path possible.
(Code wasn’t required)
3. Given a series of operations to build a project along with the time taken by each operation.
Some operations are dependent on previous operations. Find the minimum number of days
needed to finish the operation.
I wasn’t very sure of the solution I was thinking,so he said it was okay and concluded the
interview.
Tips:
1. Keep sharing your idea with the interviewer, he would help you a lot.
2. Don’t give up, you might come up with a brilliant idea with a little more thinking.
And do remember:
“If it doesn’t end well then it probably hasn’t ended yet”
I would like to thank all my friends for all the support and a special thanks to GeeksForGeeks
for their awesome website. Cheers! �
All Practice Problems for Amazon !
Subarray with given sum
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-291-on-campus-for-sde1/
722
Chapter 294
1. Given a string print the lexographically smallest possible rotation of the string.
(N square sol. Passed)
2. Balanced parenthesis
I did bith coding questions and attempted 17 mcq and got selected for next round
Out of 500 ,47 were shortlisted
1. suppose there is a matrix filled with zeros and ones then find if there is a path between
(0,0) to (n-1,m-1 )
I explained my approach(trivial dfs) Then he asked me to write a code for printing all
possible pathsI implemented it using backtracking
2. Game of nim
3. Number of all possible bst for keys 1 to n
4. number of all possible labeled binary trees for given n nodes
5. https://www.geeksforgeeks.org/dynamic-programming-set-31-optimal-strategy-for-a-game/
6. https://www.geeksforgeeks.org/check-whether-a-given-string-is-an-interleaving-of-two-other-given-strings-set
723
Chapter 294. Set 292 (On-Campus for Internship)
• Design a data structure for a server which can store atmost 100 records, 2 functions
are used to access server get(k) ,put(k,v,x).
Where k is key and v is corresponding value and x is the expiry time before which this
record cant be removed
Implement a data structure to implement these function optimally. I implemented
using self balancing bst and an unordered hash map
• Then he asked me to construct an avl tree for keys from 1 to n.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-292-on-campus-for-internshp/
724
Chapter 295
1. Write a function to find ‘a’ raised to the power ‘n’.Then he asked me to find the time
complexity of the function.
2. He was about to ask me the question of ‘finding the number of islands’- https://
www.geeksforgeeks.org/find-number-of-islands/ but I told him that I already know
the solution so he moved to the next question.
3. There are n boxes given that are 1-D. You have to find the best fit for the given item
that can fit into the box. For ex- An array of boxes is given as {7,9,12} and we need
to find the best match for the item of size 10 then the box with dimension 12 will be
our best match. I suggested him to use BST. We can arrange all the boxes in a BST
and find the successor for the given item in the BST. He then asked me to code it.
4. He then asked me about my project.
725
Chapter 295. Set 293 (On-Campus)
1. What all data structures you know.Give the real life examples of when can we use
them.
2. Write a code for preorder traversal of a binary tree without recursion.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-293-on-campus/
726
Chapter 296
1. Pivoted array search, modified that array can have duplicate values need to return
first occurance of element.
2. Is pair of given values present in BST or not?
Round 2
1. In FB when we enter person name to search then their are multiple name FB gives us
as a suggestion. Design a DS for showing these name.(gives him trie DS solution)
2. Behavioral Questions
(a) Things u learn in 3 years of experience which makes u different from fresher guy?
(b) Project description
Round 3
1. LCA in binary tree. Both elements parent must not be equal to given elements.
2. Check if pair is present in array or not. modified to return all unique pair in it.
3. Integer stream is coming find largest K element.(K is fixed)
4. Design a DS where below operation is performed in O(1) time.
(a) Insert
(b) Delete
(c) Search
(d) GetRandom
Round 4
727
Chapter 296. Set 294 (Experienced)
2. There is file of million number you have to find out largest k element.
3. Give all pair present in array. Duplicate can be present in it.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-294-experienced/
728
Chapter 297
1. Which of the following sorting algorithms have worst case nlogn complex-
ity?
Ans:merge sort,heap sort.
2. Time to insert an node after a given node in a linked list?
Ans:O(1).
3. Number of child process created when fork() system call is called n times?
Ans:2^n-1(i guess).
4. Int arr[5]={1,2}, cout<<a[2]<<a[3]<<a[4];. . . what is the output of the
following snippet? Ans:0,0,0.
5. The average time taken for searching an element in an array using linear
search assuming that the searched element is always present in the array?
Ans: (n+1)/2.
6. You will be given array ,you have to find out which of them represents a
max/min heap?
7. You are two traversals of a binary tree„you have to find out the asked
traversal? For ex: Inorder=4, 8, 10, 12, 14, 20, 22. Level order=20, 8, 22, 4, 12, 10,
14 Find preoreder? Ans:20,8,4,12,10,14,22
729
Chapter 297. Set 295 (On Campus)
8. You are given a binary search tree and a key time taken for the Searching
given key? Ans:O(log(n)) worst case for balanced BST O(n) worst case for Normal
BST (this case occurs for left/right skewed trees).
Coding Questions :
1. You are given a array of positive integers which represents heights of buildings.Width
of each building is assumed to be 1. You have to find max rectangle area of buildings.
Ans: https://www.geeksforgeeks.org/largest-rectangle-under-histogram/
2. You are given a string let say “saideep” ,s-1,a-1,i-1,e-2,d-1,p-1 is the frequency of each
character.VALUE of the string is defined as sum of squares of count of each distinct
character.value of above string is 1+1+1+1+4=8; Your task is to minimize the
strings VALUE of the string after removal of ‘k’ characters.
Ans: Its a straight forward question where you take a 256 array to store frequency of
each character ,for k times you find a maximum frequency character and decrements
its frequency by 1. After k iterations print the VALUE function you get by remaining
characters.
1. You are given a binary tree ,you have to print extreme nodes of it.? Give me an
algorithm that is robust,works fine for all cases,explain the space complexity and time
complexity of you algorithm?
For Example:
1
/ \
2 3
/ \ \
4 5 8
/ \
6 7
Output: ( 1 2 8 6 ) or (1 3 4 7)
Ans: It is just a modification of level order traversal,keep track of a Boolean flag
variable and flip it after each iteration. She then asked me write complete code neatly.
2. You will be given two linked lists that consists of digits 0-9 only in each node. Each
linked list represents a Number ,you have to add two numbers represented by a linked
list?
For Ex:
Input:
First List: 5->6->3 // represents number 365
Second List: 8->4->2 // represents number 248
Output
Resultant list: 3->1->6 // represents number 613
730
Chapter 297. Set 295 (On Campus)
I said i already know that question she skipped to the next question
Ans: https://www.geeksforgeeks.org/add-two-numbers-represented-by-linked-lists/
3. You will be given a linked list that contains loop inside it,if exists detect it and
1. You are given a string with distinct characters and you have to print all the permuta-
tions of it?
For ex: Input:”AB”
Output: AB,BA
Its a straight forward question and i gave him an back tracking approach and he
asked me to explain how that backtracking works using an example.i explained him
by taking various examples that involves corner cases and made sure that it works
for all the cases. He then asked me write complete code neatly.
Ans: https://www.geeksforgeeks.org/write-a-c-program-to-print-all-permutations-of-a-given-string/
2. You are given a maze which describes the way for a goat to reach its house.Maze is
usually a M*N grid consisting of only 0’s and 1’s .Goat initially is at (0,0) point in the
maze and it has to reach point(M-1,N-1).The only possible move the goat can make is
go RIGHT,DOWN,RIGHT-DOWN(DIAGONAL) i.e from a point (i,j) goat can move
to(i+1,j) or(i,j+1) or (i+1,j+1) point.Goat can make only one step at a time. Your
task is to find number of such paths for the goat to reach its house.
Point (0,0) and point(M-1,N-1) are abviously 1. A 1 indicates that the point can be
used and 0 indicates that the point is blocked in the sense we cannot go to the point
at any cost.
Ans: I gave him a recursive solution initially and explained him about the drawbacks
of that solution, that it takes exponential time to solve that problem.
731
Chapter 297. Set 295 (On Campus)
I then explained how i can use Dynamic programming to solve this problem and gave
him a DP solution.He was very much impressed with my solution and asked me the
time and space complexities of that solution.He then asked me write complete code
neatly.
He then gave me a coding question: You have to replace every element of an array with its
immediate smaller element to the right. If such an element doesn’t exist don’t replace it.
Ans: I gave him a stack solution which he was very much satisfied and asked me to code
taking care of corner cases. He then asked me write complete code neatly. He is satisfied
with my code and asked me to wait outside for further round.
F2F 4 ( HR+TECHNICAL ) :
He started by asking me to introduce myself and gave a coding question.It’s the tough
question
You will be given a floor say(m*n) dimensions and sub rectangles that can fit inside the big
rectangle..you have to print the floor plan for given dimensions of small sub rectangles.
He explained me that it requires construction of SLICING TREE and then printing floor
plan. He asked which all the data structures you will use to construct it and asked me think
of it.
732
Chapter 297. Set 295 (On Campus)
Ans: I gave him an stack/queue based approach .I told him that i’ll sort the sub rectangles
by lengths/breadths and push them in stack in d=increasing order. .he was very much
satisfied with my algorithm and asked me to code it.I coded it completely and showed him
. .I just solved the problem and i didn’t print the floor plan which is our actual problem. .i
then implemented the print function inside it.
He said that he’s done with the interview and asked me if any queries.
I asked him about the kinda of project he’s currently working and some casual discussion
on technologies.
PS:- Everyone knows the algorithm but it’s implementation with robust,clean code is re-
quired which covers all test cases.they will certainly give corner cases that our code fails
to execute so make sure you write a universal code.Make sure you ask any doubts if any
to clarify the given question/scenario.The interviewers are a lot helpful and they give you
hints if you are struck.
Thanks GeeksforGeeks . .It helped me a lot in my preparation.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-295-on-campus/
733
Chapter 298
Amazon Interview Experience | Set 296 (On Campus for Internship) - GeeksforGeeks
734
Chapter 298. Set 296 (On Campus for Internship)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-296-on-campus/
735
Chapter 299
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-297-on-campus-for-sde/
736
Chapter 300
737
Chapter 300. Set 298 (On-Campus for SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-298-on-campus-for-sde-1/
738
Chapter 301
The First Round was an Online Coding Round along with MCQ’s.Remember to
attempt some MCQ’s correctly in order to improve your chances in getting through this
round as the Coding questions may not be very difficult.
Q1. Find the next greatest number using digits for a given number. STL usage is allowed!
Q2. In a given array A find the maximum value of |Ai – i| – |Aj – j| where i not equal to j.
This is pretty simple!
MCQ’s were standard and were from permutation and combination and probability
mostly.Also outputs for code snippet.
There is a 5:1 selection ratio here.
739
Chapter 301. Set 299 (On-Campus for Internship)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-299-on-campus-for-internship/
740
Chapter 302
Set 299
741
Chapter 302. Set 299
list.
4) He ask me to explain binary search and proof of its complexity(O(log n)).
According to me the key for selecting is don’t stop interacting with recruiter at any cost
and be loyal with him/her.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-299/
742
Chapter 303
743
Chapter 303. Set 300 (On-Campus for Internship)
I can’t bring all the content of file to main memory. Using indexing I have to solve that
problem. I gave k-way merging approach. Now asked me to do in a different way. He gave
me hint for bst. Told me to write the code.
5. Technical Interview 4
A) You have an infinite number coming to you. Device an algorithm to get the minimum
at that time. Solved using two stack. Asked me write proper code, handle all corner cases.
B) Given the marks of a class in BST.
Subtract 5 marks from even ranked student. Asked me to code.
C) Questions from OS, threading.
And many more questions, some I don’t remember.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-300-on-campus-for-internship/
744
Chapter 304
Coding Questions:
745
Chapter 304. Set 301(On-Campus for Internship+ FTE)
746
Chapter 304. Set 301(On-Campus for Internship+ FTE)
• Given an infinite integer number line, find minimum steps required to reach a particular
point. 0 is the starting point and at ith step we can move +i or -i steps from current
position.
Tried using tree and realised it is DP problem told him the approach and complexity
and why DP and why BFS (to get minimum steps).He was satisfied with the approach.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-301on-campus-for-internship-fte/
747
Chapter 305
1st Round:
In this round the interviewer asked me the below two questions.
1.a) Given a number find the next greater number with the same set of digits.( https:
//www.geeksforgeeks.org/find-next-greater-number-set-digits/ )
I had to write the complete code covering all the edge cases.
Since I had practiced this question, it didn’t take much time to code for it.
1.b) Given a Binary Tree, convert this to a tree where each node contains the sum
of the left and right sub trees in the original tree.( https://www.geeksforgeeks.org/
convert-a-given-tree-to-sum-tree/)
For this question, first I discussed the approach, confirmed the edge cases and then wrote
the code using recursion.
2nd Round:
This round started with questions from Operating Systems.
The interviewer asked me questions on Process and Threads, Process Scheduling, Mutex
and Semaphores and Memory Management.
Some of the questions that were asked:
a) Difference between process and thread.
b) Advantages and disadvantages of using threads.
c) Difference b/w Scheduler and Dispatcher.
d) Name all the process scheduling algos and explain the Round Robin Process Scheduling.
e) At max how many threads can be active at a time in a machine?
748
Chapter 305. Set 302 (On-Campus)
3rd Round:
In this round the interviewer asked me questions on the Internship project.
He told me to briefly explain the complete project and asked various questions on the same.
Then he gave me a coding question and asked me to first explain the approach and then
code.
The question was,
You ar given an infinite stream of numbers and an integer k, at any instant of time you have
to print the top k elements scanned till that point.
I explained the naive approach of using an array of size k and then inserting the elements
at proper position thus making sure
that the array always remained sorted. Complexity O(k)
He was not satisfied with this solution and told me to further improve it ie aim for O(log(k)).
I did some brainstorm for a while and then gave the final solution to him using a min heap
of size k.
He also asked me to write down complete code for min heap.
The next question was on Caches.
He asked me to tell different page replacement policies.
Then he asked me, “How would you implement LRU Cache”?
I told him that it can be implemented using Priority Queue.
Then he cross-questioned me on Priority Queues, its internal implementation and complex-
ities.
He didn’t ask to code for it.
4th Round:
749
Chapter 305. Set 302 (On-Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-302-on-campus/
750
Chapter 306
• Given a string output reverse string (string could have multiple spaces between the
words).
Example:
i/p: I am a proud Indian.
o/p:
Indian proud a am I.
• Given a no in string format output another string which is the biggest no formed from
using same digits , otherwise print -1:
i/p:
0000
132
4312
11
o/p:
0
321
432
-1
751
Chapter 306. Set 303 (On-Campus)
• Given a link list of 0’s and 1’s sort it so that all the 0’s are at beginning and 1’s at
the end. It had to be in-place.
You cannot swap values only pointers.Order of 0’s and 1’s was to be maintained . I had
to write production level code for this with all boundary conditions checked!
• Given an array of 0’s and 1’s again and a variable k , print the size of the smallest
window which contains exact k 0’s .
– discussion about the best optimised approach .
– I solved it by storing indexes of all 0’s and calculating min diff b/w every k
elements.
• A person has to cross a road and with each step he either gains some energy or loses
some (this info is provided as an array) . Find out the min amount of energy he should
start with so that at any level his energy is not less than 1 ).
Simple question done in O(n).
• How to solve (a*b)%m , where all a,b,m are of the order 10^15. Modulo’s distributive
property is one thing .
1st approach suggested was breaking the no’s to binary as solving for eg:- [ ( 2^5 +
2^3 + 2^0) * (2^5) ] % [(2^3 + 2^2 + 2^0)] is feasible, but he wanted faster approach.
I suggested O(lg b) approach using divide n conquer (recursive solution) .
• He asked me if I know about the data structure Tier , I had heard about it and its
use but never implemented it. He explained a briefly what it is , then told me to code
its structure , its functioning (finding / adding a new word) .
Then asked a few questions on it , some cases where it will falter , some more discussion
on it.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-303-on-campus/
752
Chapter 307
MCQ’s
They were pretty simple you just need to have basic knowledge about Scheduling Algorithms,
Threads and Time Complexity. In this section major portion was from the Operating Sys-
tems.
I would suggest you go through last minute notes on OS, they were life savior for me in
Online round as well as in further round.
We were told that there will be only 2 Technical Rounds and No HR round.
Face to Face Round 1: (~1 hour)
753
Chapter 307. Set 304 (On-Campus for Internship)
– Step 2: Reverse the second half of the link list and keep the head as head2 for
the second half of the linklist.
First Half
1->2->3
Second Half after reversal
6->5->4
Now traverse both the halves simultaneously and then take a node from first list
and then from second list, do this until you reach the end of first and second list
and make new links and maintaining the links to the next Node. Asked me to
cover all corner cases.
Finally asked me to give a proper working code on paper.
• Question 2:
If one of the nodes in BST in not is correct position place that in correct position in
the bst. First by some observation I figured out that the there will 2 nodes which will
be in wrong order.
So this question became similar to Two nodes of a bst are swapped ,correct the bst. I
gave an in order traversal approach but missed some corner cases, after giving a few
he told me I am missing some more test cases, then he moved to next question.
• Question 3:
A music player has N songs , you have a random number generator rand(n) which
generates a number from [0,n-1] .Your task is to play a random song from given N
songs such that each song is played once and your program should terminate once you
have played all the songs.
– Approach 1:
We will use a HashMap to store the index of the song played and then whenever a
random song is played check its occurrence in the HashMap if is is already there
generate a random number again and do this till the size of the HashMap is N.
He told me that is a buggy code, and asked me to find out the bug.
The problem with the code is that it might end in an infinite loop in the worst
case, assume that the first time rand(n) generates a number k (k<n) and we put
that in the hashmap , now assume every time the rand(n) generates k so we will
end into an infinite loop and our program might never terminate.After a lot of
thinking, I couldn’t come up with a good approach.
Hint given by interviewer: What if you can swap some of the songs?
– Approach 2:
Step 1: Take a variable last initialize it to N.
Step 2: Generate a random number using rand(last),let it be k.
Step 3: Swap(a[last-1],a[k])
Step 4: last–;
Step 5: Goto Step 2 till all the songs are played(last!=0)By the last variable I
simply keep track of all the songs that are played(after last).
He was satisfied with the approach.
• Question 1:
754
Chapter 307. Set 304 (On-Campus for Internship)
He started with graphs asked to find the followers of a person told him to do a bfs
and some basic questions related to bfs.
• Question 2: Clone a LinkList with random pointers.
Gave him a solution using Hash Map, he was not satisfied asked me to do in O(1)
extra space.
I thought for 20 minutes but couldn’t come with the O(1) approach.
Hint given by interviewer: What if you change some links in the original list?
Again thought for about 10 minutes still couldn’t come with an O(1) approach.
Then he asked me to code the HashMap approach, while coding I figured out the approach
with O(1) extra space. Once I was done with the code I told him the other approach, he
was satisfied, code wasn’t required for the second approach.
• Question 3: If you have 2 very big numbers how will you add them? Told him
BigInteger is there in Java use that.
I : No without using that.
Take two strings and simply convert every character to digit and then add them up.
I: No you don’t have to convert a character to a digit.
Take 2 arrays.
I: Tell the constraints with the array.
Then I finally told him to use a LinkList.
And then finally told me the approach to add them without reversing the list.(Did by
recursion)
• Then there were many small questions related to quick sort, heaps, hashing, time
complexity for various algorithms.
What are different phases in Compiler?
I never expected that!
I thought for about 2 minutes and tried to collect as much as possible whatever I have
read in Compiler design. Then I gave him 4 phases of Compiler: Lexical Analyzer,
Syntax Analyzer, Semantic Analyzer, Intermediate Code generation and then told
him that I don’t remember anything more that this since I haven’t prepared CD and
studied a long time ago.
• Then he asked me questions from OS.
What is Threading?
Why thread better then process?
What is thrashing?
What is LRU?
And some more basic questions on OS.
755
Chapter 307. Set 304 (On-Campus for Internship)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-304-on-campus-for-internship/
756
Chapter 308
• Coding Question 1: Find next greater number with same set of digits
• Coding Question 2: Merge two sorted arrays with O(1) extra space
MCQ’s
They were pretty simple and straight forward. 5 questions were from general aptitude like
probability, permutation and combinatorics. Rest of the questions were from Data Structure,
Algorithm and C and C++ output questions. Reading GeekQuiz helped me a lot.
Around 300 students took the test out of which 21 were shortlisted. I was also one of them.
We were interviewed the following day.
Face-to-Face Interview 1(~1 hour)
The interviewer asked me to introduce myself. After I gave my introduction, he went straight
to the questions.
Question 1: A program to check if a binary tree is BST or not
Given a binary tree, we need to check if it’s a binary search tree. He wrote the following
function
bool isBST(Node *root)
I asked him if I could modify the function template to include min and max values. He said
that I can modify the function template. So I gave my approach as described here. After
757
Chapter 308. Set 305 (On-Campus for Internship)
reviewing the solution, he asked me to explain it with an example. I drew a small tree and
explained it to him. He was satisfied and we moved on to the next question.
Question 2: Maximum sum such that no two elements are adjacent
Given an array of positive and negative numbers find the maximum sum in the array such
that no two elements are adjacent. The question can be found here.
As soon as he gave the question I said it is a Dynamic Programming problem. He asked
me to write code. I wrote the code by using a dp array of size n (size of array) and I gave
a top-down approach. He thoroughly checked if my code could handle all the corner test
cases. He asked me to run the code for array of size 1 and 2. I explained it to him. He was
satisfied and we moved on to the next question.
Question 3: Find a given word in a matrix of characters.
Given a NxM matrix and string s, check if the string is part of the matrix. We can move to
top, left right and bottom from a given cell. The question is similar to this.
Initially after giving the question I said we should use Depth First Search. But he gave me
a case where it won’t work and asked me to modify the approach. I said BFS and he asked
me to write code. I wrote the code by handling all edge conditions. But I missed the visited
array part. He read my code and gave me a case where it would run into an infinite loop.
Now, I found out what was missing and said I have to include the visited array. He was
satisfied and asked me to add that part to the code.
After this, the interview was over. He asked me if I had any questions for him. I asked him
a few questions and we were done.
Out of 21 students, 12 students were selected for the second interview. Fortunately, I was
also selected.
Face-to-Face Interview 2(~1 hour)
The interviewer read my resume and asked me to introduce myself. After I gave my
introduction, he went to the question.
Question 1: Count Possible Decoding of a given Digit Sequence
Let 1 represent ‘A’, 2 represents ‘B’, etc. Given a digit sequence, count the number of
possible decoding of the given digit sequence. The question can be found here.
I gave my approach using Dynamic Programming. He asked me to reduce the space com-
plexity. I gave an approach like finding nth Fibonacci number. He was satisfied. Then, he
asked me to generate all the possible decoding instead of counting them. I gave my approach
using backtracking and he was satisfied.
Question 2: Identify the classes required to play chess game.
This was like a general question. I said four classes like – pieces, board, clock, player and
game. He asked me to identify the attributes and functions of each of the class and how
they interact with each with other. I told them. He was satisfied.
Finally, he asked me if I had any questions for him. I asked him a few questions and we
were done.
That was all for the interviews.
758
Chapter 308. Set 305 (On-Campus for Internship)
General Tips:
Don’t be nervous when speaking to the interviewer. And don’t think for a long time. Speak
out your thoughts so that they can help if you go wrong. Preparing from GeeksforGeeks
helps a lot.
Best of Luck!
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-305-on-campus-for-internship/
759
Chapter 309
Round 2:
In round 2 following q’s were asked
1) Given n points in 2 d space and two functions JOIN(A,B) and istransitvelycon-
nected(A,B).
Join assigns A,B to same set while istransitvelyconnected(A,B) checks wether belong to
760
Chapter 309. Set 306 (On-Campus)
Round 3:
Two questions were asked
1) Find path with root to leaf sum as equal to target.
2) Given an infinite string defined by function f(x)=x+”0�+f(complement x) find k’th bit
Solved first one easily,got stuck in second one so solved using brute force…
However,managed to reach 4 th round
Round 4:
Interviewer was little arrogant to my surprise..he kept staring and grinning while I solved
the problem..he also said since it is 12:30 I wont waste time asking to introduce you.although
ALL other people had theoretical round involving OS,CN,DBMA concepts I was asked to
solve coding problems again..
I was asked my favorite Data structure..I said tree..
1) Find shortest distance between two nodes of binary tree..after 2 mins. I said just find
LCA in one traversal and then the path of the nodes in other traversal..
soln is O(n)..he asked me to write LCA code ..i wrote in O(1) space using recursion…maybe
he wanted solution in 1 traversal..although he did not tell me that..
2) The RAM of pc is 4 gb and file is 40gb in size .File contain numbers..sort the numbers..I
came up with dividing files and using heap to sort all the file..
Asked me to writ the data structure…gave something like this..
struct heap
{
int element;
FILE *f;
}
heap arr[];
761
Chapter 309. Set 306 (On-Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-306-on-campus/
762
Chapter 310
763
Chapter 310. Set 307 (Off-Campus)
In any round they will discuss your project in dept. And asks for alternatives for technologies
used in your application.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-307-off-campus/
764
Chapter 311
1. Given a binary tree print it in vertical order. The problem is stated here: https:
//www.geeksforgeeks.org/print-binary-tree-vertical-order/
2. Given a linked list convert it into given format:
1->2->3->4->5->6
to
1->6->2->5->3->4
Round 2:
It was an in-person interview.I was asked only one question. He asked me about various
approaches. With least space complexity, least time complexity, different data structure
usage for the following problem:
https://www.geeksforgeeks.org/trapping-rain-water/
Round 3:
1. I was asked to implement a queue with any data structure, discuss its time complexity,
why the particular DS was chosen etc.
2. Second question was to find the number of islands given a graph, i.e. find number of
disconnected graphs given a graph.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-308-sde/
765
Chapter 312
1. The interviewer asked me what data structures I know. Then he asked me the appli-
cations of graph.
766
Chapter 312. Set 308 (On-Campus for Internship)
2. Suppose there is a social networking site like Facebook. Every user gets some friend
recommendations (i.e. People you may know!). Now, if there is a user A and he has
100 friends and each of his friends has got 5 other friends,A can get these 500 recom-
mendations. But the condition is that he should only get the top 10 recommendations
with whom he has the maximum number of mutual friends(If A and B are friends and
B and C are friends, then A and C have a mutual friend, B). Suggest an efficient data
structure for this and how to implement it. The implementation should be flexible as
at any moment, any user can make new friends and he may also unfriend someone!
3. Applications of heap. Insertion in a heap ( insertion of strings in a heap, priority is
decided lexicographically). Time complexity of insertion.
Thanks GeeksforGeeks �
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-308-on-campus-for-internship/
767
Chapter 313
Set 309
768
Chapter 313. Set 309
i/p: 5 6 3 10 9 12
o/p: 6 10 10 12 12 12.
i/p:12 3 4 10 6 5
k = 4
o/p: 3 3 4
I told him the Queue approach he is not satisfied. Then I started with dequeue ,he stopped
me and asked me to use data structure other than queue. I told him min heap approach.
He seemed to be satisfied .He asked me to write a production level code for that.
2. A new tree data structure is given in which each node has two values top and bottom,
when all the nodes are arranged in tree, the top vales of all nodes must follow BST while the
bottom values must follow min heap. elements can be inserted in any order(not the order
of arrival).
I gave my solution. He was satisfied and asked me to write a production level code for that.
Finally, “do u have any questions?”
Round 4:(1hr 30 min Face to face)
1. The celebrity problem: https://www.geeksforgeeks.org/the-celebrity-problem/
2. Count possible decoding sequence: https://www.geeksforgeeks.org/count-possible-decodings-given-digit-sequence/
3. We are receiving a stream of data from a social network, how will you display k max
persons based on number of friends?
He was satisfied with my approach of max heap.
Finally, “do u have any questions?”
After each interview some were eliminated.
Thanks to geeks for geeks.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-309/
769
Chapter 314
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-310-for-internship/
770
Chapter 315
Amazon Interview Experience | Set 311 ( On Campus for Internship and FTE) - Geeks-
forGeeks
Recently Amazon came to our college for both FTE and interns. Here I am sharing my
interview experience. There was 1 online round and 4 F2F interviews. Online round had
2 coding questions and 20 MCQs (based on OS, sorting complexity, Recursion, DBMS ,
geometry etc).
F2F 1
He introduced himself and asked me about my project which I had done in Samsung Research
Institute this year.
Then He asked me these questions
1. Suppose there is only one platform and n number of trains. So at any point of time only
1 train will stay in platform. N time intervals are given which represent the timing duration
of n trains.You have to find what is minimum number of trains that have to be postponed
such that no collision take place.(full code was required covering all corner cases)
2. Suppose a string “abca” is given. Print all of its permutation such that no 2 same
combination will be printed twice. (Considering string can have duplicate characters).(full
working code required)
3.Asked me what DS I will use to evaluate a given expression? Then Asked to write the
code of Infix to Postfix conversion.
4.There is an array of N numbers ranging from 1 to N. Only 1 number is missing, return
the index of that number.
F2F 2
Asked me many question regarding my project for first 10 minutes.Then asked the following
questions
771
Chapter 315. Set 311 ( On Campus for Internship and FTE)
1. A matrix is given containing only 1 and 0. So whenever you access a 0 make the entire
row and column as 0.
I was using o(n2) space first, he said to use o(n) space only.
2. Given a binary tree find the minimum root to leaf height.
I told him a level order solution where I was en queuing the level also with each node. He
said not to push the levels with each node, so I kept on delimiter which I was pushing only
after one entire level traversing was over and returned as soon as I got a leaf node.
F2F 3
This interview was taken by the senior most person among the interview panelists. I was
nervous while entering the room and as a result I messed up the interview.
He directly started asking question without any introduction which made me more nervous
�
1. He wrote one nested recursive program(around 12-15 lines) on a page and asked me to
draw the recursion stack of that program and show him in what order one function is called
and stored in the stack and in what order it is returned back to its callee function. And to
prove what is the space complexity through that recursion stack.
I was nervous and was loosing confidence so could not solve it properly.
2. Find the second largest and second smallest in a given array in single traversal.
3. Find power(x,y) without using pow function.(divide and conquer approach was required)
After this round I did not get a call for the last round. Some of my friends were asked
questions on basic BFS application, topological sorting , LRU cache implementation , Boxing
stack problem in the last round.
Tips
1. Questions asked will be very easy at most of the times. Be confident. Whatever be the
question you were asked try to solve it as long as you can, share your approaches with your
interviewers.They will certainly help you out.
2. Have a clear idea of your project, they will ask you several questions regarding that.
3. Work very hard. �
All the best �
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-311-on-campus/
772
Chapter 316
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-312-for-sde-ii/
773
Chapter 317
1. Find the kth smallest element in row wise and column wise sorted matrix. (No Heap
solution)
2. There is a given data with time and number of orders at that time and it will random.
Then there will be a query of how many orders placed between a given interval of
time.
Second Round:
1. https://www.geeksforgeeks.org/minimum-number-of-swaps-required-for-arranging-pairs-adjacent-to-each-oth
2. There given a list of strings out which we have to print the unique strings. Unique
string is a string which is not repeated.
Third Round:
It was a discussion on my current project and the challenges I faced and how I managed
when I am unable to meet the deadlines.
1. There given a 2 Lists with int values. We need to find the longest chain. Eg: L1 = {
2,7,4,8,9,10}, L2 = {1,2,8,9,4}. Here the solution is 2 (chain is 2,4 or 8,9). Because 7
is present in L1 which is not L2.
2. Given a equi-weighted uni directed graph and need to find the max distance possible
from a given node.
Fourth Round:
774
Chapter 317. Set 312 (Off Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-312-off-campus/
775
Chapter 318
1. Palindrome Partitioning– Spilt a string into minimum number of substring such that
each substring is a pallindrome.
2. Find the diameter of a binary tree
4th Round
Detailed Discussion on current role and responsibilities.
Discussed complete architecture of my current project- in terms of classes and methods,
databases and cache used and then discussed improvements that i could suggest in architec-
ture of my project.
5th Round
Discussion on current role and responsibilities. Discussed on architecture of my previous
776
Chapter 318. Set 313 (For SDE II)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-313-for-sde-ii/
777
Chapter 319
778
Chapter 319. Set 314 (For FTE)
1. Firstly, he asked me about my favorite subjects. I told him operating system. Then he
asked me about process scheduling algorithms and then he asked me how will you allocate
memory to a newly formed file. I told him about first fit, best fit and worst fit. He asked
me what are the advantages and disadvantages of these.
2. Then he asked me a design question. Let’s say you have a 13 floor building and it has 6
lifts in it, you have to design an algorithm such that if a user click the lift button, any of
the available lift should reach to him in minimal time.
3. Then he asked to give the design for top k trends of twitter of facebook. I told him that
i’ll keep a trie for storing the count of the number of users associated with a particular trend
and will keep this count in max heap and will extract top k trends.
Solution for design varies from candidate to candidate. so you should design your own
solution rather than searching solution on google.
F2F 4
This was a Bar raiser round and it was telephonic. He asked about my project and we had
discussion on it in detail . After 40 minutes he asked me to write the full production level
code on implementing LRU using circular linked list. It was easy and i had done that in
second round also, so i wrote the whole code and he was satisfied.
verdict: selected �
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-314-for-fte/
779
Chapter 320
Set 315
1
1 1 1
1
size 2 :
1
1
1 1 1
1
1
Find size of largest plus pattern in given 2D mattrix which has only 0s &1s.
Round 3:
1. check if a binary tree is BST or not :https://www.geeksforgeeks.org/a-program-to-check-
if-a-binary-tree-is-bst-or-not/
780
Chapter 320. Set 315
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-315/
781
Chapter 321
782
Chapter 321. Set 316 (Off-Campus)
It is similar to fibonacci series. Interviewer asked various ways to implement the same –
Recursion, 1-D array, with 3 variables and complexity of each.
2) Design recommendation engine.
It’s like auto suggestion. I gave the trie approach. The interviewer seemed fine with this
approach and asked me to write full code with time and space complexities. Implementation
of Tries:
https://www.geeksforgeeks.org/trie-insert-and-search/
Round 4 (Managerial Round – Over video call)
Tell me about yourself.
Current work
Which project you liked working the most.
Any case where you had conflict with your manager.
Any idea/technology suggested by you to your team which then got implemented and worked
out.
Any case when you had to work out of your comfort zone.
The most critical feedback received from your manager/team members.
What do you do to enhance your technical knowledge apart from your project work.
And many more.
783
Chapter 321. Set 316 (Off-Campus)
cases while writing code, know time and space complexities, have better approaches for
solving same problem and so on.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-316-off-campus/
784
Chapter 322
• First Ques- So what you know about Amazon- I wasn’t prepared to start my interview
with this ques. But I had read months earlier how Amazon was established and was
able to satisfy him with answer.
• 2 ques- Tell me about Summer Intern at wipro- It took around 20 min. Deep discussion
on project, all in and out.
• 3 Ques- How does the program gets compiled internally, I told him I have not studies
this part as my branch is ECE.He then asked me what have you studied- I told him
DS algo ,OS, Networks and convinced him that ECE is strongly related with CS in
terms of Algorithm.
• 4 ques- As i told him that I like competitive coding, He asked tell me 1 quess you have
solved- I told him- Find the K-most frequent occurring word till now in a running
stream of words by using Trie(modified) and Heap concept. He asked why I am using
min heap and not Max heap and I gave the reason.
• Everything about Min Heap-> Insertion deletion modification.
• Given data How will you sort them. I told him quick sort , merge sort are possible
ways.He asked which you will prefer I told him QuickSort .Why not Merge sort? I
told him because of external memory use but then he asked that can’t we do it in-place
, later on I was able to do inplace merge sort and he again asked which algo you will
prefer I told still quicksort because it is more Cache Friendly and he was satisfied.
• Given 100 gb data, you need to sort them how will you proceed. I told him external
sorting and he straight away told me I don’t want merge sort. Then I tried to twist
the situation by asking what type of data is available. He was in doubt why am I
asking that, So I told him if all the data is in limited range then I can simply apply
counting sort and he was impressed as well he forgot about the actual question. �
• He was done with the interview and said do you have any ques. ME- What role will
be playing in the team if selected.
785
Chapter 322. Set 316 (On-Campus)
Round 2
I went for 2 round without wasting time as Spot On offers were to be given. Interviewer
was slightly weired and he straight on went for the ques.
There is data available for different vehicles and all vehicles have n parameters which dis-
tinguish it with other vehicle so given huge data you need to separate them in different
lists based on some parameters matching. How will you proceed->Then he said 3 parame-
ters are there and if all 3 parameters match then they belong to same list.
I told him lets sort the data according to first parameter then for then sort acc to 2 para
and so on..(something like Radix sort).
He told me to use Hash-Map and model the whole idea….building the structure for each
vehicle and then use key to do hash-mapping.
I implemented it but due to too much overwriting, He was not looking impressed but he
told its correct.
DO u have any questions.
After this Round I was rejected.
TIPS-
1. Please be prepared for Hash_MAP it is very important to have deep knowledge as this
part is rarely covered in.
2. Try to write clean codes and by clean code I mean you shoud use good variable name,
dont scribble much and try to write comments along with it.(I made a mistake here.)
3. You should know all in and outs of the project and remember interview can ask any
project.
4. Puzzles don’t matter much…
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-316/
786
Chapter 323
Round 2:
Round 3:
787
Chapter 323. Set 317 (SDE-1 Off – Campus)
1. Initially I was asked questions about the work I had done, the projects I did and some
managerial questions.
2. Then I was given a coding problem to solve. They use Collabedit tool in phone screen
interviews where the same screen is shared by both interviewer and interviewee.
Ques : Print all the non-repeating words out of two given sentences.
Eg. Statement 1: I have a blue pen.
Statement 2: I got a red pen.
Output : have blue got red
Discussion : I suggested the hashing approach. The interviewer asked to implement
the same.
788
Chapter 323. Set 317 (SDE-1 Off – Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-317-sde-1-off-campus/
789
Chapter 324
• 20 MCQs
• 2 Coding Questions:
– Find zeroes to be flipped so that number of consecutive 1’s is maximized
GFG Link: https://www.geeksforgeeks.org/find-zeroes-to-be-flipped-so-that-number-of-consecutive-1s-is-
– Find the first circular tour that visits all petrol pump (Similar to this)
GFG Link: https://www.geeksforgeeks.org/find-a-tour-that-visits-all-stations
2 Technical Rounds:
They take time in declaring results as they ensure that all eligible candidates make it to the
Technical Interviews. Technical Rounds also consists of coding. Here, you need to discuss
your approach with the interviewer and then code it on paper.
1st Technical Round:
General question of Tell My About Yourself. Following this were technical questions mainly
coding.
Q1. Find the position of the rightmost set bit.
I gave various approaches, firstly dividing by 2. Then they asked for a solution using
bit operations. Gave them solution using OR. GFG Link: https://www.geeksforgeeks.org/
position-of-rightmost-set-bit/
Q2. Time complexity of Binary Tree: Searching, Inserting
2nd Technical Round:
Again asked Tell My About Yourself. There were 2 coding questions asked.
Q1. Large number sum using Linked List.
2 Approaches: Reversing the linked list and then adding or Recursion. Gave both the
solutions. Then the question was: In case of a billion digits, which would you prefer?
Recursion has a lesser time complexity but, a normal system won’t be able to operate so
790
Chapter 324. Set 318 (For SDE Intern)
much on recursion, as there will be a stack overflow. Hence for a billion digits we have to
go with reversing the linked list and then adding each digits.
GFG Link: https://www.geeksforgeeks.org/add-two-numbers-represented-by-linked-lists/
Q2. Find an element in a strictly row sorted and column sorted 2 dimensional array
without brute force.
GFG Link: https://www.geeksforgeeks.org/search-in-row-wise-and-column-wise-sorted-matrix/
Q3. Questions on Sorting and Searching algorithms complexity.
Q4. Questions on Networking
What is BGP(Border Gateway Protocol)?
What is Link State Routing? How does it work?
What is OSPF?
TCP/IP model and OSI model.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-318-sde-intern/
791
Chapter 325
792
Chapter 325. Set 319 (On-Campus)
these 2 contacts are same. Find groups of same contacts. I suggested having a hashmap with
parameter string as key and index as value. Then when we encounter matching strings in
the hashmap, connect this 2 contact indexes as we do in Disjoint set Quick Union approach.
In the end. find matching contacts using find operation.
Technical round 3:
This interview was mostly based on resume discussion. He asked me about my internships
and projects and also asked me some OS questions. Then he gave me a chess problem. I am
given initial positions of 8 pawns and a knight. I have to answer whether I can remove all 8
pawns using my knight. Then he simplified question and now only 1 pawn is there. I wrote
full code for recursion to solve the problem but time complexity was exponential. Then he
asked me how do I find the minimum number of steps in which I can remove this pawn. I
modified my existing code to return a number of steps now.
Technical round 4:
This was kind of like HR round. Initially, he asked me about my latest internship work
and started with specific questions. What was the toughest challenge I solved during any
of my projects? What kind of problems you encounter when working in a team and how
can those be resolved? Did you ever write non-maintainable code and why did you write it?
Did it ever happen to you that you suggested some good approaches but they were thrown
to trash by higher authority and how did you tackle with that?
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-319-campus/
793
Chapter 326
Face to Face
1. Two colors are given(yellow, blue), we have to color such that no consecutive blue
color is painted
Given the arrival and departure time of various trains in a station. Calculate the
minimum number of platforms required such that no train has to wait for another
train to vacate the platform.
The question basically means calculate the maximum number of trains that would be
present in the platform at any given time.
Answer
sort the arrival time and sort the departure time, keep a count initialized to 0. compare
the first element of the arrival time with the first of departure, increase the value of
count if the value at current Index at arrival is less than the value index at departure
and increment the arrival index, and vice versa. Keep the maximum count that you
see.
794
Chapter 326. Set 320 (Off-Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-320-off-campus/
795
Chapter 327
The first part were 6 questions. Each with a provided code where it asks you fix and make
changes so it can compile/run correctly. Most of these problems were errors with syntax,
parameters, operators, and others along the same lines. The second part were 24 questions
on patterns, logic, and some others like concluding a given passage. Everything during the
test is monitored and questions can be returned to if moved on. Before starting it gives the
option of selecting a programming language from C, C++, or Java. For me I chose C. If
you ever coded at a university in a beginner/intermediate computer science class, then you
should have no problem getting through this. I just graduated last month so everything was
fresh to me still. I reviewed several old homework assignments that helped out a lot with
the basic understanding of algorithms and memory allocation. A lot of people told me to
study from the “Cracking the Code Interview” by Gayle, which I vaguely looked over and
found it did not help as much for this assessment, though it might for the next interview
processes. The most difficult aspect for me was the limited amount of time, especially the
first portion that requires you to read code line by line. I highly suggest you take your
time to read the question once and carefully, then answer if you can and if you cannot then
skip it and return if time permits. Other than that, I found it far simpler than what I had
expected and overly prepared for. They said I will be contacted for the next interview step
within a week.
All Practice Problems for Amazon !
796
Chapter 327. Set 321 (Online Assessment)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-321-online-assessment/
797
Chapter 328
Round 2 (F2F):
1. Given a stack of integers of size n, you have to sort it using only push and pop
operations (you are not allowed to copy the numbers in auxiliary array and sort it and
then push back in array). (I gave O(n^2) approach and O(1) auxiliary space).
2. Stepping on stairs: A valid move is defined as either a single step or 2 steps. Starting
from 1st stair you have to reach nth stair in minimum valid moves. I gave dp approach
then rolled down it to Fibonacci formula which can be solved in O(log(n)) time using
Matrix Exponentiation.
3. Stepping numbers: A stepping number is defined as a number in which the absolute
difference between the consecutive digits is not greater than 1, A stepping number
cannot be a single digit number. You have to find the number of stepping numbers
between n1 and n2 where n2 > n1 and n2, n1 > 0. First I gave brute force approach
i.e. traverse from n1 to n2 and print i if i is a stepping number. They asked me to
optimize it, after a little while I came up with BFS solution, where a node in graph
(directed) represents a number and nodes directly connected to it have one more digit
appended at the end. Stop when number dequeued from the queue is greater than n2.
4. Iterative version of Tower of Hanoi. I gave stack version of TOH. Since recursion uses
recursion stack. I removed recursion and used stack to imitate recursion instead. They
were satisfied with the solution.
798
Chapter 328. Set 322 (Off-Campus)
Round 3 (F2F):
1. In any point of time print the first non-repeating number in a stream of numbers. It
took me quite a while and after little brainstorming I came up with solution using
DLL and map.
2. Delete node in a BST. I had forgotten how it was done so again I had to think hard,
realized that deleted node must be replaced with its inorder successor to maintain the
BST property and coded the solution.
3. This was the most exciting round. They seemed happy with my approach.
1. General Discussion.
2. Infix to Postfix conversion.
3. Return a maximum length sequence containing consecutive numbers from a binary
tree. i.e.
90
/ \
1 66
/ \
2 67
/ \ /
5 4 68
/ \
99 100
I had the hunch but was not able to code it at first, so he asked me to do it later then after
some discussion, i was given 15 min to complete it and finally in those 15 min it clicked and
I managed to do it.
Some advice:
799
Chapter 328. Set 322 (Off-Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-322-off-campus/
800
Chapter 329
• Ques 1 : You are given an array of size n. Now print the number of distinct elements
in the array for every frame of size k.
• Ques 2 : A binary tree and a number, say k are given. Print every path in the tree
with sum of the nodes in the path as k.(A path can start from any node and end at
any node, i.e. they need not be root node and leaf node; and negative numbers can
also be there in the tree)
After two weeks, I got a mail to come for the face to face rounds of interviews.
Round 2 (F2F) : 1 hour
Interviewer was very friendly. I was tensed before entering into the room but after talking
to him for a minute, I started feeling comfortable. He started with his introduction and
then asked me about myself and the work I am doing in my current company.
Then, he moved on to the coding questions.
• Ques 1 : A binary tree is given.You need to print every path in the tree starting
from root with sum of the nodes of an path equal to a given number, k.(Numbers can
be negative too)
Sol : https://www.geeksforgeeks.org/given-a-binary-tree-print-all-root-to-leaf-paths/
801
Chapter 329. Set 323 (Software Development Engineer – Off-Campus)
• Ques 2 : A linked list is given in which every node has two pointers, one to its next
node and the other one, random pointer, pointing to some other node in the linked
list.You have to clone the given linked list.
Sol : https://www.geeksforgeeks.org/a-linked-list-with-next-and-arbit-pointer/
• Ques 1 : A browser is being designed and you have to implement the history feature
in that, which will have two functions, one is to fetch recent 100 urls ( getHistory() ),
and other one to update that recent 100 urls list whenever a url is hit ( updateHistory()
).
• Ques 2 : An array is given and it can be of four types :
(a). increasing
(b). decreasing
(c). first increasing then decreasing
(d). first decreasing then increasing
Without traversing the array we need to tell its type.There was a long discussion on
this question.
802
Chapter 329. Set 323 (Software Development Engineer – Off-Campus)
a name and he searched for the paper on his laptop there only.Discussion on the project was
approx 45 minutes long.
After discussing the project in detail, he gave me a coding question and we discussed that
question also for approx 45 minutes.
Question – There is a number given in the form of a string.Number can be any long.Now I
have to tell just greater number of the given number which is a palindrome also.
Sol : https://www.geeksforgeeks.org/given-a-number-find-next-smallest-palindrome-larger-than-this-number/
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-323-software-development-engineer-off-campus/
803
Chapter 330
804
Chapter 330. Set 324 (For SDE2)
necessary classes where will u use polymorphism, where inheritance, multithreading, syn-
chronised approach if needed, socket connections
other things that surfaced and he asked as interview goes : round robin load balancer,
hash-map based load balancer, two layer caching, nosql db, design patterns, solid principles,
ACID property, CAP theorem etc.
interviewer was a senior person and knew a lot. I was nervous in this round but answered
well.
B) many behavioral questions
3. third round (1 hour): technical
A) many behavioral and “what if you were in a situation” questions
B) Given an array of words which comes in a dictionary of some language in the same order.
tell if its possible?
ans. represent characters of words as a graph and find out if graph is cyclic (cycle in directed
graph)
the interviewer was very supportive. He gave me few important hints in terms of question
understanding.
4. fourth round (1 hour): technical
he asked me what you like , I said array questions � He started laughing.
A) given an array of integers and two types of queries point update and range sum?
ans: I said binary indexed tree then he asked for other ways I said segment tree, He asked
more , I said prefix array or sqrt decomposition.
he asked me to write code for the same. made some variations like lazy propagation.
B)topological sorting. given a words of dictionary tell alphabet ordering.
C) many behavioural questions
Hr came and told me that we are done for the day one more interview is there which was
on next day.
Hr was very supportive she gave me some constructive feedback and told me to get prepared
well and come next day as next day was
with a Bar Raiser.
5. fifth round (1 hour): technical+ design + behavioural, Bar Raiser
A) asked tree related questions , how to represent and model a tree.
B) Design a Netflix type system. start from HLD to LLD. detailed discussed happened on
this
discussion on search, video serving, authentication, encryption, dns lookup, which caching
strategy would you chose?
serving multi quality video etc.
C) few behavioural questions.
Few things to remember:
1. for technical go through geekgsforgeeks practice test and interview experiences
2. for design have a look at carreercup
3. review OS concepts.
4. recruiters and hr is very supportive
5. prepare for behavioural questions well.
6. prepare “do you want to ask any questions?”
All Practice Problems for Amazon !
805
Chapter 330. Set 324 (For SDE2)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-324-sde2/
806
Chapter 331
Set 325
1) Contiguous subarray
2) Non Contiguous Subarray
3rd Round(ftf)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-325/
807
Chapter 332
808
Chapter 332. Set 326 (For Application Engineer)
809
Chapter 332. Set 326 (For Application Engineer)
Debugging – How will you debug the issue whatever you have troubleshooted.
4. If there is sudden increase in the requests count in the system and you need to answer
to the higher authorities, how will you handle the situation?
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-326-application-engineer/
810
Chapter 333
811
Chapter 333. Set 326 (For SDE II)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-326-sde-ii/
812
Chapter 334
1. Given an array find the maximum consecutive and non consecutive sum and
print them.
2. Given a matrix find the number of 1’s in the maximum island MAT[i][j] = {0,1}.
Round 1 Data Structure —
1. Given a tree return the number of elements for the level with the maximum ele-
ments.
PS : all null nodes between two non null nodes need to be counted and null nodes can have
null children which also can be counted.
eg– [null,2,1,null,null,3,null] in this level all nodes between 2 and 3 will be counted i.e. 5
2. Asked about what data structures I knew and what data structure will I use to make a
cache.the answer was Hashing.
3. Asked what data structure would i use for maintaining cricket scores.
the answer was priority queue.
Round 2 Algorithms —
813
Chapter 334. Set 327 (Off-Campus for SDE-1)
Asked me the word breaking problem which I couldn’t solve and this round didn’t
go well.
Round 4 Managerial —
1. Asked about my current company and work done over there.
2. Asked me a problem to convert Integer to Roman while handling all the corner cases.
3. Asked about process and Threads
4. I asked about the team and kind of work to be done
I would like to thank GeeksforGeeks to provide such a huge variety of problems and a
progressive way to approach any problem.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-327-off-campus-sde-1/
814
Chapter 335
Ex:
1
/ \
2 3
/ \ \
4 6 7
815
Chapter 335. Set 328 (For SDE-1)
2nd Round
1. Given a large file having strings(for understanding, given an array of strings). Find the
string which repeats the most. Ignore the case.
2. Given the link-list and integer value ‘k’, reverse every k nodes of the list.
Ex. k = 3, list: 1-2-3-4-5-6-7-8
ans: 3-2-1-6-5-4-8-7
3rd Round
1. Questions on my projects.
2. Given a binary tree with each node having parent pointers. Find the LCA of two nodes.
4th Round
1. Given a 2-D grid, number of steps to take, say k and intial position of a Robot. print the
paths possible from initial position after k steps. Robot can move in top, right, left, bottom.
In one path, robot can’t move to the location it has previously visited.
2. Check if a binary tree is balanced. Balance criteria was difference of height between left
and right subtree should be <= 1. 3. Given a binary tree, a node of that tree, and integer
k. Print all the nodes which are at distance k from that node. NOTE: there is no parent
pointer in the node. 5th Round
1. Behavioral Questions. Read front pages(before technical stuff) of Cracking the coding
interview book. Prepare them well.
2. Given a string, count all the palindromes in that string. Only consider substring palin-
dromes.
Thanks to geeksforgeeks for helping me prepare for interviews.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-328-for-sde-1/
816
Chapter 336
2. He asked do you like DP. I said yes so He asked me a puzzle. There is a stream of
integers and two players are playing. Each player can take one integer from either of
the corners. I need to tell if player A is playing first then what will be his maximum
score. I gave him recursive approach he said its perfectly fine. He asked me to optimize
my solution cause it was exponential finally I gave him a dp approach he was satisfied
and then told me to write full bug free code for the same.
3. N number of identical nodes are given. You need to calculate how many no of binary
trees are possible?
817
Chapter 336. Set 329 (Off-Campus for SDE-1)
I was currently working on Blockchain so he asked me about this technology cause its
totally new and amazing tech so he was pretty impressed. He asked if I have any question
for him. I asked several question related to his work and Amazon visions.
Then he asked me explain current company project and project architecture, my role in
team etc. Guys prepare well for behavioural questions, they look for culture fit.
Coding question:
Print the vertical sum of a binary tree.
https://www.geeksforgeeks.org/vertical-sum-in-binary-tree-set-space-optimized/
Result : I got the call after 3 days and hr said congratulations, you are placed and It was
like dream came true.
Thanks to my parents, Upendra Bhaiya and Prajakta for all the support. I want to thank
geeksforgeeks team, it’s an ideal platform for preparing coding interviews.
All Practice Problems for Amazon !
818
Chapter 336. Set 329 (Off-Campus for SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-329-off-campus-sde-1/
819
Chapter 337
Set 330
820
Chapter 337. Set 330
2. https://www.careercup.com/question?id=5693863291256832
I gave him a solution where I start with empty string and in each step I pick the most
frequent character and add it. I also check if the character I am adding is same as the
previous character. He was satisfied with my approach and did’t ask me to write code. He
said this question is for testing problem solving skill.
3. https://www.geeksforgeeks.org/print-nodes-top-view-binary-tree/
He asked whether I came across this question and I said no. I gave the solution using bfs
but I used HashMap which was not necessary. He asked me to think on using a simpler
data structure. I struggled a bit but finally came up with set to store elements.
Round 3 (Managerial):
1. Tell me about yourself.
2. Tell me a situation where you had conflict with your manager.
And many more behavioral questions.
3. A DBMS question about Amazon’s product catalogue. I had no clue how to approach
this. She asked if I know any DBMS concepts and I said “No” and told her that I am from
a Non-CS background.
Overall I didn’t feel good about this round and my confidence went low. Luckily, my first
two rounds went well and they decided to give me another chance by taking another coding
interview.
Round 4:
1 http://stackoverflow.com/questions/2473114/how-to-find-sum-of-elements-from-given-index-interval-i-j-in-consta
At first I gave a solution using segment tree (overkill ) . He asked me to think of a simple
solution. And then I remembered the solution where we keep an auxiliary array to store
the cumulative sums. Then the queries can be answered in constant time.
2. https://www.geeksforgeeks.org/find-the-longest-substring-with-k-unique-characters-in-a-given-string/
I already solved this problem previously and I immediately told him the solution using
two-pointers.
Round 5 (Managerial):
1. Tell me about yourself.
2. What was the hardest bug that you have encountered. How did you fix it.
And many more behavioral questions.
3. https://www.careercup.com/question?id=64946
This is an object oriented design question. I practiced these type of questions before going
to the interview from “Cracking the coding interview” book and felt comfortable during the
interview.
Compared to the first managerial round, this went pretty smooth.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-330/
821
Chapter 338
Amazon Interview experience | Set 331 (1 Year Experienced for SE-1) - GeeksforGeeks
A big big thanks to geeks for geeks for constructing this platform where candidates find
suitable question sets.
1. 1st Round (Coding round on hacker rank) :
Two questions. Each of 100 marks. Total time given was 2 hours.
Question 1: https://www.geeksforgeeks.org/find-length-largest-region-boolean-matrix/
Question 2: https://www.geeksforgeeks.org/largest-sum-contiguous-subarray/
2. 2nd Round (Tech) :
Two questions. Here the basic knowledge of data structures and algorithm is tested to
determine whether candidate is eligible for onsite interview rounds or not.
Question 1: https://www.geeksforgeeks.org/find-zeroes-to-be-flipped-so-that-number-of-consecutive-1s-is-maximize
Question 2: https://www.geeksforgeeks.org/a-program-to-check-if-a-binary-tree-is-bst-or-not/
3. 3rd Round (Tech):
Two questions. Knowledge of algorithms and data structure was tested. Along with it,
production level code had to be written on paper and it was to be made sure that no edge
cases remain uncovered.
Question 1: https://www.geeksforgeeks.org/print-nodes-at-k-distance-from-root/
Question 2: https://www.geeksforgeeks.org/print-nodes-distance-k-given-node-binary-tree/
4. 4th Round (Tech):
Same checks as present in 3rd round. Since i did not perform well in the 2nd question of
3rd round, more stress on my coding part was given in this round. They were thoroughly
checking my code and pointing all the edge cases if any.
Question 1: https://www.geeksforgeeks.org/clone-linked-list-next-arbit-pointer-set-2/
Question 2: http://stackoverflow.com/questions/6179635/what-is-a-good-data-structure-for-storing-and-searching-2
5. 5th Round (Hiring Manager – Tech & Non Tech):
Checks were same as above rounds. Along with those, whether the candidate was a good
fit at amazon was checked.
822
Chapter 338. Set 331 (1 Year Experienced for SE-1)
Question 1: Given a stream of integers, at any point of time, fetch the count of integers
which are smaller than a given number.
Example :
at time t1:
stream : 1, 4, 3, 2, 6, 7
input : 5
output : 4
at time t2:
stream : 1, 4, 3, 2, 6, 7, 2, 1, 5
input : 8
output : 9
Question 2: HR Questions
– give an instance where your manager and you disagreed.
– give an instance where you outperformed yourself.
– expiain your project and your role in it.
– explain the most difficult project you’ve faced.
6. 6th Round (Bar raiser Tech and Non Tech) :
This guy will thoroughly check everything starting from code, algorithm, data structure,
behavior etc. It is necessary of every candidate to crack this round.
Question 1:
Given the below pattern, write a recursive code for all values of n.
N = 3
- - -
- -
- - -
N = 4
- - - -
- -
823
Chapter 338. Set 331 (1 Year Experienced for SE-1)
- - -
- -
- - - -
N = 5
- - - - -
- -
- - -
- -
- - - -
- -
- - -
- -
- - - - -
N = 6
- - - - - -
824
Chapter 338. Set 331 (1 Year Experienced for SE-1)
- -
- - -
- -
- - - -
- -
- - - - -
- -
- - - -
- -
- - -
- -
- - - - - -
825
Chapter 338. Set 331 (1 Year Experienced for SE-1)
Question 2:
Explain internals of hash map's put method and write code for it.
Question 3: HR Questions
3. Take time to code but make sure once done, the code is impeccable.
5. Try to cover as many geeks for geeks amazon interview sets as possible. As you can see my inte
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-331-1-year-experienced-se-1/
826
Chapter 339
Round 4: F2F
1. Isomorphic binary tree check.
2. Count all possible decodings of a string of digit.
3. Given log files consisting of product bought and customer id, print top k purchased
items at any time. If billions of items are there and it is not possible for a single ma-
chine to handle them then how will you handle this condition. Discussed several approaches.
Round 5: F2F
1. Top view of binary tree.
2. Given an expression number of different ways to evaluate the expression.
Exp. 1+2*3, can be evaluated as (1+2)*3 or 1+(2*3)
Later he asked me to find out all the possible answers as well.
827
Chapter 339. Set 332 (Off-Campus)
Round 7: F2F
1. Hotel booking problem.
2. Next greater number with same set of digits. O(n) solution was required.
3. Discussion on TRIE.
I would like to thank GeeksForGeeks for providing a variety of questions of all topics.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-332-off-campus/
828
Chapter 340
Second question was of moderate level in which input is an expression string and you have
to evaluate that given string is valid. If yes return the value of the expression, else return
-1.
Input : 5+7*2
Output : 19
Input : 5++4
Output : -1
829
Chapter 340. Set 333 (For Internship)
Input: 100klh564abc365bg
Output: 564
Answer: I gave him a o(n) approach, he gave me a few test cases and tried to prove my
logic wrong, for one case I was wrong because I had used int data type so as to rectify the
mistake, I told him that I would be using long int instead. Then I asked him if I can use
string.h library? He said yes sure, then I gave him iotn() approach. Then he told me to
write the code.
Question 2:
You have been given a generator string ab from which any number of strings can be generated
recursively by inserting ‘ab’ at any location. You have been given an input string to check
if that given string is valid or not.(i.e. generated by given with given string.)
eg.
Input: aabbab
Output: valid
Input: abbaab
output: Invalid
Answer:
First I gave him o(n^2) approach then he told that he wanted o(n) approach. After about
5 minutes I gave him o(n) approach involving two pointers. Then again he told me that I
would be traversing the input twice. What if I wanted to achieve it in one pass? Afterwards
I gave him solution using count variable. (It was PDA problem there is also a stack based
solution but I didn’t give that solution because that solution didn’t strike at that time)
Then he asked me,”Do you have any question for me?”
I asked him about job profile,his projects and his experience in Amazon
Round 3: Technical Interview 2(1 Hour)
After one hour of round 1 they told me that I was selected for round 2. Just like round 1
he asked me to introduce myself. Then he started asking technical questions.
Question 1: Delete a node from doubly circular linked list.
Answer: It was easy question, so I asked him about constrains, like if there was any condition
that node can exist or not and data constrain. After listening to constrains I wrote a code
covering all possibilities and hence we checked few test cases manually for that code.
Question 2: He observed that I was little tensed he asked me the reason of my nervousness.
I answered saying, as it is my first interview and I was feeling anxious. He asked me why
why was that so, though few companies had visited campus before Amazon, guessing that
I must have had at least one interview experience.
Answer: I told him that I was not eligible because of low pointer then I told him that why
my CPI was low and how I’m good at coding. �
Then He encouraged me which was very good and positive thing for me(usually interviewer
will do it if you show your positive side). Then he asked few question related to my hobbies
to make my mood fresh.
Coming back to technical stuff …
830
Chapter 340. Set 333 (For Internship)
Question 3: You have been given stock prices for n days and find optimal buy and sell day
i.e. maximize the profit.
Answer : I told him that I have solved similar question in Morgan Stanley Hackathon, Then
I gave him o(n2) approach and told that when I implemented this approach in the contest I
got TLE(time limit exceeded) message hence I had modified it and found a o(nlogn) solution
which got AC(all correct) in contest. Then I explained o(nlogn) solution using STL. He told
me not to use STL and asked me if I can solve this question in o(n)? I replied I shall
try. Then after 10 minutes, with dp approach I successfully solved that question. We then
checked some test cases.
After this question he asked me if I had any questions. Taking reference from first interview
we discussed for around 10 minutes about projects currently going on in amazon and his
experience in amazon.
(I think this question matters a lot because this question reflects your confidence about
selection as well as your interest.)
Couple of days after the interview I received a mail stating I was selected for the internship
hope you will also get a similar mail.
How to prepare for internship?
Quant and Verbal Aptitude:
indiabix.com is more than enough.
You can also use RS Agrawal books.
Technical Aptitude:
Any book of DSA and DBMS you can use.
Data structures made easy is awesome and enough for DSA
You must solve MCQs on quiz.geeksforgeeks.org
Coding Round:
This is totally different from MCQs. You have to write and debug code, so practice is very
important for this round. To study algorithm and data structures’ implementations refer
geeksforgeeks, also try to solve questions on practice.geeksforgeeks.org
For standard algorithms follow codemonk series by hackerearth.
Logic development usually takes more time so try to practice on codechef and hackerank.
Also try to participate in live contest of codechef (every months codechef long challenge).
Technical Interview:
In technical interview you should be aware of commonly known data structures and algo-
rithms. Learn that from geeksforgeeks and implement on codechef. If you are prepared for
coding round then preparing for interview is a cake walk and all you have to be is confident.
To answer the coding questions impressively I would suggest you to go through the career-
cup questions once.
‘Cracking the coding Interview’ is best book for tips of technical interviews. Also if you have
studious friends’ circle, try to conduct mock interviews with friends. (And to be honest,
everyone gets serious once internship procedure starts so you can easily manage that.)
Lastly I would also suggest coding on interviewbit.com if time allows.
Few Tips(Specially for SY’s reading this) :
try to Keep your CPI above 8 else you will miss some opportunities. And another thing
CPI matters only for qualification after that CPI is just a number nothing else . So TY’s
reading this if you don’t have decent CPI then tie your shoes for coding (MY CPI was just
7.8).
831
Chapter 340. Set 333 (For Internship)
Try to code on codechef and hackerank and try to participate in live contest.
Wish you all the best! �
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-333-internship/
832
Chapter 341
Amazon Interview experience | Set 334 (For 4.5 Years Experienced) - GeeksforGeeks
Round 1:
– Given binary tree. Find level with maximum sum
– List of modules with Dependencies given. Order the execution of modules (Topological
sort)
Round 2:
– Questions on Projects, Managerial questions
– Design Chess game. After basic design, complicated things by adding various functionali-
ties
Round 3:
– Deep design level discussion on one project that I have worked on
– Design cricinfo live score page
Round 4:
– Clone a binary tree which has random pointer as well
– Design Cache library
Round 5:
– Minimize cash flow among set of friends.
– Questions on Projects, Managerial questions
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-334-4-5-years-experienced/
833
Chapter 342
Set 335
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-335/
834
Chapter 343
Set 336
835
Chapter 343. Set 336
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-336/
836
Chapter 344
837
Chapter 344. Set 337 (For SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-337-sde-1/
838
Chapter 345
Amazon Interview Experience | Set 338 (1st Round for SDE-1 in Delhi) - GeeksforGeeks
1st Round – Pen and Paper
Q1: http://www.geeksforgeeks.org/boundary-traversal-of-binary-tree/
Q2: http://www.geeksforgeeks.org/print-possible-strings-can-made-placing-spaces/
O3: http://www.geeksforgeeks.org/sum-of-two-linked-lists/
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-338-1st-round-sde-1/
839
Chapter 346
Round -2 F2F
1) About previous projects and role.
2) In- place rotation of 2D Array by 90 degree clockwise.
3) About Amazon- what are the different projects in amazon.
Round-3 F2F
1) Find sum of all elements in a matrix except the elements in row and/or column of given
cell?
2) Print top view of tree without hashing.
Round-4 F2F Design round
1) If N-files are given containing sorted number list and files are adding at run time. design
a program if 1 st time run then gives min number , 2nd time run give 2nd min number ,
3rd time gives 3rd min number and so on
write a program
Round-5 Design and Coding
1) Design Book My show.
2) 1 problem of their project which will be solved by using map and list.
3) Your Role in previous company, design of your project, flaw in your design and improve-
ments , your strength and improvement area
All Practice Problems for Amazon !
840
Chapter 346. Set 339 (For SDE 2)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-339-sde-2/
841
Chapter 347
Amazon Interview Experience | Set 340 (3.5 years experienced for SDE 1) - GeeksforGeeks
Recently I have gone through interview with Amazon Chennai for Amazon FIRE TV team.
Here is my positive experience.
Round 1(written):
1. https://www.geeksforgeeks.org/run-length-encoding/
2. https://www.geeksforgeeks.org/find-k-th-smallest-element-in-bst-order-statistics-in-bst/
3. https://www.geeksforgeeks.org/count-substrings-with-same-first-and-last-characters/
Round 2:
1. https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/
2. It’s a two player game. Both the players are equally intelligent to win the game. Give n
no. of stones. A player can choose either 1 stone or k stones or l stone (1<k<l). Suppose
player ’A’ starts game then challenge was to identify the player who will win the game.
Player who picks the last 1 stone or last k stone or last l stones win the game.
Round 3:
1. https://www.geeksforgeeks.org/counting-inversions/
2. https://www.geeksforgeeks.org/print-matrix-diagonal-pattern/
3. http://algorithms.tutorialhorizon.com/dynamic-programming-minimum-cost-path-problem/
Round 4 (Bar Raiser)
1. Detailed discussion on current company project.
2. https://www.geeksforgeeks.org/find-maximum-path-sum-in-a-binary-tree/
Round 5 (Hiring Manager)
1. Design ATM machine.
2. Design a queue using only one stack.
3. Discussion on process & threads, Inter process communication, Lots of discussion on
scheduling algorithm, their implementations, data structures used to implement scheduling
algorithms, scheduling algorithms in real time distributed systems & implementation.
4. Lots of behavioral questions like why amazon, why you are leaving current company.
842
Chapter 347. Set 340 (3.5 years experienced for SDE 1)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-340-3-5-years-experienced-sde-1/
843
Chapter 348
844
Chapter 348. Set 341 (Off-Campus for SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-341-off-campus-sde-1/
845
Chapter 349
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-342-off-campus-sde-1/
846
Chapter 350
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-343-sde-1/
847
Chapter 351
848
Chapter 351. Set 344 (For SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-344-sde-1/
849
Chapter 352
850
Chapter 352. Set 345 (For SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-345-sde-1/
851
Chapter 353
852
Chapter 353. Set 346 (For SDE-1)
struct Trie {
int count[2],
bool isleaf;
Trie *child[26];
Trie() {
count[0]=count[1]=0;
isleaf = false;
for(int i=0;i < 26;i++)
child[i]=NULL;
}
};
853
Chapter 353. Set 346 (For SDE-1)
I would like to thank my friends and geeksforgeeks who are always with me helping all the
time,
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-346-sde-1/
854
Chapter 354
Amazon Interview Experience | Set 347 (1.8 Years Experienced for SDE1) - GeeksforGeeks
Below is the summary of interview round conducted by amazon. Although i am not able to
remember correctly since its almost 2 months.
1) Written Test
Check if Linked list contains loop.
Create Balanced binary search tree from sorted array
2) F2F (Technical)
Stream of coordinates are given. you need to identify k nearest points for given coordinate
at any point of time
3) F2F (Hiring manager)
Discussion about project
Project which has business impact
Conflict with manager/seniors
4) F2F (Technical)
Given dictionary of alien language. You need to find order of alphabets based on dictionary
– Topological sorting
DS for identifying min from given array for index range x to y.
5) Telephonic (SDM)
Detail discussion about projects
Project which made you rockstar
What you prefer to use for communication between android and backend server –
XML/JSON ? why ?
6) Telephonic (Bar raiser)
Discussion about projects
Conflicts with manager/team
Your role in projects
855
Chapter 354. Set 347 (1.8 Years Experienced for SDE1)
Given array of characters. Identify string with minimum length which covers all characters
present in the string
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-347-1-8-years-experienced-sde1/
856
Chapter 355
857
Chapter 355. Set 348 (For SDE II)
858
Chapter 355. Set 348 (For SDE II)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-348-sde-ii/
859
Chapter 356
860
Chapter 356. Set 349 (For SDE I)
4. Explain heapify function of heap sort. Then explain with code what happens when you
remove one element(max/min) from the heap.
5. Have you ever faced the situation when you did not meet the deadlines, but you thought
you were good enough and were on the right track?
7. Have you ever faced the situation when you had to struggle to meet the deadlines? How
did you divide/make progress with the work?
Round 3 (Hiring Manager):
1. Zigzag print of a binary tree (https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/
)
2. Rearrange a string such that no two same characters are adjacent to each other ( https:
//www.geeksforgeeks.org/rearrange-characters-string-no-two-adjacent/ )
3. Client calls server but gets delayed response. What could be multiple reasons? How
could you improve upon them?
Round 4 (Hiring Manager):
1. Can you explain the situation where you have pushed/written your code and your manager
didn’t approve of it, but you thought you had written the right code? What did you do
then?
2. Have you been in a situation where you convinced your manager for something?
3. There is a call/request which takes some extra time in replying. Why could it possibly
be? How do you remove that?
4. Explain caching. What happens when cache is full? Implement LRU cache. Write the
code. ( https://www.geeksforgeeks.org/implement-lru-cache/ )
5. How do you manage work with strict deadlines? If ever you faced such situations.
6. What aspects do you have in your mind when you want to join amazon? What are your
expectations out of it?
7. If you are given some work, how do define and manage it.
8. What will be your course of action if you are assigned some task which you don’t know
at all?
Bar Raiser Round:
1. Given an array of integers, replace every number with the next higher number to its right.
If a number can’t be replaced, we leave it as-it is.
For example, the list: 5, 2, 1, 4, 6, 7 needs to be changed to 6, 4, 4, 6, 7, 7.
4 different approaches were discussed and codes were to be written.
2. Why do you want to switch?
3. Why amazon?
4. Questions about current company, current project, team size, your roles and responsibil-
ities, etc. were asked in almost all the rounds.
All Practice Problems for Amazon !
861
Chapter 356. Set 349 (For SDE I)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-349-sde/
862
Chapter 357
863
Chapter 357. Set 350 (For SDE I)
864
Chapter 357. Set 350 (For SDE I)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-350-sde/
865
Chapter 358
Amazon Interview Experience | Set 351 (Off Campus - For SDE I) - GeeksforGeeks
I attended the referral drive in Delhi, so we had to report to 10:00 AM at Amazon’s office.
ROUND 1: Written – Pen & Paper (11:00 – 12:00 PM)
You have to write a short description first of your approach, put comments if necessary to
explain that line’s logic. Full Optimize Code should be written covering all the edge cases.
Also mention the complexities.
Q1. Sorted Array to Balanced BST.
Q2. Detect and Remove loop in linked list.
ROUND 2: Face to Face (02:00 – 03:30 PM)
This was the Technical Round, start with your basic approach and then move further to
optimized ones. Interviewer will expect you to write fully fledged code (the optimized
approach one) covering all the edge cases and also derive it’s complexities. If he’s not
satisfied with any of the space and time complexities he will urge you to provide him that
solution, and this happens a lot in Amazon’s interviews.
Q1. Given a number N, you can do three operations like (N-1, N/2, N/3) find the minimum
number of steps in which N can be reduced to 1 using these three operations.
Minimum Steps to reach 1.
First gave him recursive approach, gave him space time complexities. Then told him dp one
and it’s space time. Then he told me to code the dp approach.
Q2. Max Sum Path across two sorted arrays.
Gave him the solution using space O(m+n) and time O(m+n), wrote the code for it. Then
he demands to solve it in O(1) space and O(m+n) time, spend some time and coded it too.
ROUND 3: Face to Face (05:00 – 06:30 PM)
Again Technical Round, this round was more DS specific, we have to write fully optimized
code which will cover all test cases.
866
Chapter 358. Set 351 (Off Campus – For SDE I)
867
Chapter 358. Set 351 (Off Campus – For SDE I)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-351-off-campus-sde/
868
Chapter 359
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-351-off-campus-sde-2/
869
Chapter 360
870
Chapter 360. Set 352 (For SDE I)
Trie is a way and then we had discussions on Trie and search, insert etc in a Trie.
Then he asked me to code it using a Trie:
https://www.geeksforgeeks.org/auto-complete-feature-using-trie/
Then we discussed about databases. What are normal forms?
How will you design a database with books and authors (many to many relationship).
How do we query for the author with the maximum number of books?
What is a deadlock and what are ways to avoid it?
Give me a real life example of a deadlock.
Explain to me any single project in which you had to meet a deadline and what was your
course of action?
There was one more round after this and that was the Bar Raiser actually. The 5th point
mentioned in the initial post was just a technical interview.
He asked me why amazon?
Have i ever been in a situation where i went against my mentor in a project and what was
the result?
How do i keep myself motivated during tough projects?
How to meet deadlines?
How to make sure the work done by you in a project is easily understandable by a person
after you leave the project?
These were the coding questions: Convert infix to postfix and evaluate postfix. He wanted
me to assume nothing (the input string may not be valid and the code was to report so).
GeeksforGeeks helped me the most during my preparation time.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-352-sde/
871
Chapter 361
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-353-sde-2/
872
Chapter 362
Input : A = [1, 2, 3, 4, 7, 9]
B = [0, 1, 2, 1, 1, 4]
Output : [4, 5, 5, 6, 6, 6]
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-354-sde-2/
873
Chapter 363
Answer will be – 3
It went well. I was able to answer all of them. They asked me write production level code
for each of them. Take care of all the end cases. Three out of six were able to make it.
Round 3 (F2F) – This round was grilling and was again on programming standards:
1. Print the top view of binary tree. https://www.geeksforgeeks.org/print-nodes-top-view-binary-tree/
874
Chapter 363. Set 355 (For 1 Year Experienced)
Round 4 (Hiring Manager) – In this round, they focused on my experience and previous
company’s work.
All behavioral type of questions like:
1. How do you measure your success in the whole year?
2. Mention some of the negative and positive feedbacks from you manager.
3. Why you want to leave the firm so early? Why Amazon.
4. Questions on my projects and achievements in current company.
Hints: Just do not blame you current company as answer to any question. A clever way to
deal this round is make them realize you are quite good for amazon.
P.S. Some research on Amazon before the interview would be great.
Round 5 (Bar Raiser) – This was my final round. It was mixture of behavioral and
coding.
Behavioral question were almost same what I mentioned above.
Discussions on my Final year project and what new I can add to it if I am given a chance
to improvise it.
Some coding questions:
1. Given two strings, find the uncommon characters in them using single hash map.
2. Given data of millions of people, (name, age, M/F etc.) Develop an API that will have
age range as input and yield the count of people under this range as output.
Thanks Geeksforgeeks for all the references. You people are doing great!
Key points:
1. Just write clean and crisp code, whenever asked to code considering the end cases.
2. Maintain continuous discussions with interviewer. He/She will help you whenever needed.
All Practice Problems for Amazon !
Maximum sum Rectangle
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-355-1-year-experienced/
875
Chapter 364
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-356-6-year-experienced/
876
Chapter 365
Amazon Interview Experience | Set 357 (For 2.5 Years Experienced) - GeeksforGeeks
Some time back I went through an interview for Amazon.com for SDE-1 role, and here is
my experience to help other aspirants :
Written – Pen & Paper Rounds
Had to write production level code in any programming language of my choice, covering all
the edge cases, and clearly mentioning the complexity of my code.
�Q1. https://www.geeksforgeeks.org/lowest-common-ancestor-in-a-binary-search-tree/�
Q2. https://www.geeksforgeeks.org/remove-minimum-number-characters-two-strings-become-anagram/
Q3. Given an array, print the Next Just Greater Element for every element. The Next just
greater Element for an element x is the just greater element on the right side of x in array.
Return the same element if there is no greater element present on right side, or if same
element is present again on right side (in case of duplicates)
For e.g. given input array : 3,5,8,4,2,6,3
output should be : 3,6,8,6,3,6,6
Solved it using Binary search tree
Face to Face Rounds�
Interviewers were very very helpful, and were focused on approach, they will ask basic brute
force solution first, then an optimum solution, after that they may increase the complexity
of problem a little bit, and if you are able to explain your approach satisfactorily, then will
ask you to write production level code in any programming language of your choice, covering
all edge cases using pen and paper :
�Q1. Find an element in an unsorted array such that all left elements are smaller and all
right elements are greater. O(n) time complexity solution is required.�
Q2. Find kth smallest element in row wise column wise sorted matrix. Discussed both min
heap and max heap approach with complexity of both.
What if there are duplicate elements in matrix, and we have to consider all duplicate element
877
Chapter 365. Set 357 (For 2.5 Years Experienced)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-357-1-5-years-experienced/
878
Chapter 366
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-358-off-campus/
879
Chapter 367
Use max (previous element’s exclusive + arr[i]) idea. See Geeks For Geeks or Tushar Roy
video if needed.
(Did it in
o(n) for each query, by normal for loop traversal
o(log(n)) for each query, by sorting and using Binary Search we can pass TLE (Time Limit
Error) then finally, I solved it using Hashing and then do like counting sort algorithm so
o(1) for each query (Because question had maximum space complexity as 256MB so it
won’t be a problem) MOST OPTIMAL ONE.
FACE TO FACE INTERVIEWS:
4 Totally = 3 technical, 1 technical + Bar raiser rounds
First Round: (1 hr.)
880
Chapter 367. Set 359 (On-Campus)
• Merge 2 sorted linked list into sorted one (Optimize code further)
• Write code for the same by covering All Edge cases (Avoid wild pointers)
• A modified DFS with recursion question
• You want to ask any questions?
• U have 2n players, they compete with each other, each player has a rank, what can
you tell about the winner?
(Question was same as this, I asked many clarifications (received stress then answers) and
tried Graphs, Sorting players based on Ranking he said it’s not required, demanded efficient
one then I solved using Tournament Trees (2n is the clue to use tournament tree) He was
very satisfied.
• Write a code to convert a palindrome number to next immediate higher number and
it’s a palindrome too e.g. 1221=> 1331 (Think about edge cases like 99, 191 before
coding, that will reduce no. of strikes on paper, in case of 9, u have to propagate carry
to next elements)
881
Chapter 367. Set 359 (On-Campus)
• First received a compliment from interviewer for my fast coding skill on paper (previous
panels review).
• Do you like android or iOS? Me: Android! Then take your phone write a code to
simulate Android pattern locking, took my phone and understood what patterns
are possible then
• What and all will happen when you boot up your PC? (Tell from BIOS stage)
• What is kernel?
I explained everything I knew, finally I explained Android Phone Kernel too. He was very
impressed and was like stopping further simple questions.
U have a dictionary of words (Not necessarily in order given in our English dictionary)
How will u search for word (Used topological sort and explained why and how it works he
was convinced)
882
Chapter 367. Set 359 (On-Campus)
It was all done in one day. I thank Geeks for Geeks so much for helping me for my placement
preparations. It was and is very helpful!!
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-359-on-campus/
883
Chapter 368
884
Chapter 368. Set 360 (On-Campus)
6. When two threads access a code at the same time, what happens. How is it prevented?
7. Difference between mutex and semaphore.
8. Priority Inheritance and Priority Inversion.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-360-campus/
885
Chapter 369
Set 361
Round 1 :
1. Given 2 array of size m , n , find the pair from diff array with minimum difference
2. given the dialer of a feature phone and a dictionary of words , find the string suggestions
after dialing n numbers .
3. Verify if the Tree validates the definition
parent_node.data = left_node.data + right_node.data
Round 2 :
1 . how to handle server scaling up to sudden increased of request
2 . how to handle scaling the data
3. Design BookMyShow tables .
Round 3 :
1 . given an array of Strings , not necessarily in any order , find out if the string create a
chain , such that first last char of a string is the first character of another and thus making
a chain including at least all string
2 . Given a party with n people , a given function Knows() , such that
A knows B : true if a knows B
A Celebrity would be a person who knows no one but is known by all
Find out the celebrity if he exists in the party. I would like the mail id to be kept confidential.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-361/
886
Chapter 370
Set 362
887
Chapter 370. Set 362
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-362/
888
Chapter 371
889
Chapter 371. Set 363 (On-Campus for Internship)
-OOPS
-Basics in Network
-Testing Questions
-Design Patterns
-drawing design pattern for the project done
-Why Amazon?
-Any Questions from me(HR)?
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-363-campus-internship/
890
Chapter 372
891
Chapter 372. Set 364 (On-Campus)
iv) Troubleshoot: in amazon.com a person X has ordered for 10 items.oly 2 among them
were delivered to X.but it is showing in amazon’s mobile app, as all 10 items are delivered.at
the same ti,e it shows the correct status in amazon’s website….find why??
5th round: Technical Hr with Hiring manager:
In this round he ll question u technically, but he ll check ur way of answering and attitude.He
ll just check whether u ll be suitable for that position.Ur knowledge doesnt matter here..Ur
attitude speaks.
i) Validate the cancel order option in amazon.com
ii) Draw the flow diagram of ur project and explain it briefly. How ll u provide security for
ur project.and many questions related to my project.
iii) troubleshoot : you are unable to see the latest details in ur mobile app.it still shows the
old details.What are all the reasons?
iv) troubleshoot: what all the things u ll do , if u couldn’t open ur mobile app?
All Practice Problems for Amazon !
Even and odd elements at even and odd positions
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-364-campus/
892
Chapter 373
893
Chapter 373. Set 367 (On-Campus for Internship)
2. Given a linked list separate even and odd numbered nodes such that even numbered
nodes are at the front of the list and in order followed by odd numbered nodes.Since it was
also a straight forward question. I explained two approaches and he was satisfied and asked
me to code it.
https://www.geeksforgeeks.org/segregate-even-and-odd-elements-in-a-linked-list/
Count triplets with sum smaller than X
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-367-campus-internship/
894
Chapter 374
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-368-phone-onsite/
895
Chapter 375
896
Chapter 375. Set 369 (On-Campus)
Around 50 students were shortlisted for technical interview. The interviewer asked for my
resume and asked me about one of my project works. Then he moved on to asking programs.
1. Determine the row index with minimum number of ones. The given 2D matrix has only
zeroes and ones and also the matrix is sorted row wise. I could come up with solution with
time complexity N square. He gave me hints to traverse in different manner(diagonally) and
asked me to keep a broad perspective while thinking for the solution.I tried for some more
time but failed, then he moved on to the next question.
2. Given a binary tree and 2 nodes. To find whether the 2 nodes are cousins or not. I came
up with a solution using recursion. He was satisfied with my approach.
My friends got questions like bottom view of tree, best technique to sort first 5 elements of
array with 1 million elements(brute force), mostly questions related to trees were asked.
After the 2 questions he asked if I had any questions for him. I asked him how I had
performed in this round. He gave a smirk and replied, “The HR will tell you”. � Then I
asked him if it was allowed to change domain in Amazon to which he replied, “Yes, but only
once you are permanently hired, not as an intern”. This round was 1.5 hours long.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-369-campus/
897
Chapter 376
Amazon Interview Experience | Set 370 (On Campus for Internship) - GeeksforGeeks
Round 1: Online Round(90 minutes)
There were 20 MCQs and two coding questions. MCQs were mostly logical reasoning,
running time and DS/Algo. There were also 2-3 OS, 2-3 DBMS and 1 networking MCQ.
2 coding questions-
1- Magic numbers are defined as either powers of 5, or sum of unique powers of 5. Find nth
magic number. Eg: 5,25,30,125,130 etc.
https://www.geeksforgeeks.org/find-nth-magic-number/
2- Print matrix in diagonal form.https://www.geeksforgeeks.org/zigzag-or-diagonal-traversal-of-matrix/
Round 2: FTF Interview(Around 1 hr)
First the interviewer told me to introduce myself. After that he asked 2 coding questions.
1- Given a binary tree and a node of that tree, find all nodes at a distance d from the given
node. Pointer to root node is given.
I took a lot of time to solve this question. The interviewer found mistakes and told me, and
I corrected them or changed my approach slightly. After almost 45 minutes I was able to
write the correct code.
2- Given an array of integers, find the first non-repeating number in the array.
I gave him the hashmap based approach and he told me to write code. I did so. After
that, he told me to find the answer in a single linear traversal of the array. I discussed a
lot of approaches but none of them were satisfactory. I couldn’t come up with the correct
approach. (Later on when someone asked him the solution, he said that he himself doesn’t
know, but maybe a very complex solution exists. I’m still not sure on that. Maybe he just
wanted to check how much we can think. :p)
<Round 3: FTF Interview(Around 30 minutes)
The interviewer asked me what subjects I like. I told him ds algo but he didn’t want to hear
that. So he asked what else and I said DBMS. Then he asked me what is a transaction, how
898
Chapter 376. Set 370 (On Campus for Internship)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-370-campus-internship/
899
Chapter 377
900
Chapter 377. Set 371 (For SDE-2)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-371-sde-2/
901
Chapter 378
Round 3 (written)
I was called in Amazon office after few days (very nice office)
Tree traversal with several ways.
Few linear array problem
I believe this round was just for warmup.
Round 4 (45 Mins)
Brief description of current project: this time he was more focused on technologies and tools.
He asked every technology I mentioned in deep.
Top view of given binary tree: you can find the problem here
902
Chapter 378. Set 372 (For SDE II)
An html format string was given where I have to find output of given queries.
Ex.
Pratik
Queries would be like: GET name, so output would be Pratik. (something like that)
Round 5 (Manager)
After some formal discussion he came up with his question “Design pattern for chess game”
for which I wrote few classes and explained approaches for the game like peer to peer and
client-server but he was not satisfied. This round didn’t go well.
I could not make it but it was very good experience, All interviewers were so friendly and
helpful.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-372-sde-ii/
903
Chapter 379
1. https://www.geeksforgeeks.org/trapping-rain-water/
2. https://www.geeksforgeeks.org/total-number-of-possible-binary-search-trees-with-n-keys/
, Just the formula and its derivation was discussed
Round 2
1. https://www.geeksforgeeks.org/majority-element/
2. https://www.geeksforgeeks.org/boundary-traversal-of-binary-tree/
Round 3
1. Discussion on my project, its design, challenges faced, what important decisions I took
that worked and other such behavioural questions.
2. After this discussion, I was given a problem to design Truecaller kind of system
Only these rounds happened on 1st day. Later I was called to complete the other 2 rounds
Round 4
Round 5
904
Chapter 379. Set 373 (For SDE 2)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-373-sde-2/
905
Chapter 380
So output will be 3.
2. You are given with a large paragraph and N words.
You have to find a min length subparagraph of the paragraph which contain all those N
words in any order. Here length of a paragraph is the count of words in the paragraph.
FIRST F TO F ROUND
1. Tell me about yourself (tell them about your projects and all).
Then he asked 2 coding questions:
1. Given an array in such a way that first the element stored in array is in increasing order
and then reach to a peak element after which elements stored in decreasing order.
Then he asked me to search a given element in this array gave some approach he was satisfied
and asked to code I did the same.
906
Chapter 380. Set 374 (On-Campus)
2. He asked me to design a snake and ladder game for 2 player and code it.
SECOND F TO F ROUND
First he asked me about my projects in detail. Then he asked 2 coding question
1. Print a month of a calendar such that starting day of the month, number of days in a
week and number of days in a month Is given you can consider it as an alien calendar which
can have more than 31 days in a month and more than 7 days in a week like this
THIRD F TO F ROUND
1. Given a string print all the permutations of the string
2. Stream of integer is given, each time when you get an integer you have to print the kth
largest integer I gave 2 approach first using insertion sort and a k length array and second
using binary min heap of k element he gave some hints also at last he asked me to code I
did the same.
FOURTH F TO F ROUND
1. He asked about projects and some question related to OS
2. Then he asked given an array of strings in sorted order in some alien language where we
don’t know the ordering of the alien alphabets form these given strings we have to deduce
907
Chapter 380. Set 374 (On-Campus)
and print the ordering of all the alphabets. I used graph and topological sort he was satisfied
and asked me to code I did the same.
3. Then he asked given an array of string count the number of anagrams I gave solution for
2 strings then he asked solution for the main problem I was struggling then he helped me
and we reached to solution.
SOME TIPS
1. Be confident amazon have amazing interviewers they won’t let you fell nervous
2. Try to communicate in English don’t worry about the fluency.
3. Try to improve your problem solving and coding skills
4. Don’t just mug up or read the solution try to get the concept behind any problem and
practice approach building.
5. During interview don’t jump to the solution direct try to start with brute force and keep
talking to interviewer while you are building an approach he will let you know what he
wants.
6. Listen carefully your interviewer and follow his instruction only and catch his hints also.
7. The only thing amazon wants in a candidate is analytical and problem solving skills
8. You can use any programming language I used java
9. For preparation I used hackerrank, geeks for geeks, and book karumanchi of ds and algo.
NOTE: Please excuse my English �
Find the Highest number
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-374-campus/
908
Chapter 381
Amazon Interview Experience | Set 375 (On Campus for Internship) - GeeksforGeeks
Recently, Amazon visited our campus to recruit interns and FTEs. There were 3 rounds in
all – 1 Online Round followed by 2 F2F Interviews
Round 1: Online Round (90 minutes)
There were 2 coding questions and 20 MCQs mostly on Time Complexities (Master Theo-
rem), Logical Reasoning, Data Structures and Algorithms, around 2 from OS, DBMS and
Networking each.
The 2 coding questions were:
1) Find the sum of lengths of non-overlapping contiguous subarrays with k as the maximum
element.
Ex: Array: {2,1,4,9,2,3,8,3,4} and k = 4
Ans: 5
{2,1,4} => Length = 3
{3,4} => Length = 2
So, 3 + 2 = 5 is the answer
2) You are given an array A where A[i] (1-based indexing) denotes the number of chocolates
corresponding to each station. When we move from station i to station i+1 we get A[i]
– A[i+1] chocolates for free. Note that if this number is negative, we lose that many
chocolates. We can only move from station i to station i+1 and that too if and only if we
have non-negative number of chocolates with us. Given that cost of one chocolate is Rs. P
, our task is to find the minimum cost incurred in reaching station n from the first station
(station 1).
Ex: A: {1,2,3} and P = 10
Ans: 30
To reach station 1 from the starting station, we need to buy 1 chocolate
To reach station 2 form station 1, we get A[1] – A[2] = -1 chocolates i.e. we lose 1 chocolate.
Hence, we need to buy 1 chocolate.
909
Chapter 381. Set 375 (On Campus for Internship)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-375-campus-internship/
910
Chapter 382
Amazon Interview Experience | Set 376 (On Campus for Internship) - GeeksforGeeks
Amazon visited our campus(Jadavpur University) to recruit interns and FTEs. I’m sharing
my internship interview experience.
There were 3 rounds in all – 1 Online Round followed by 2 F2F Interviews.
Online Round(90 min on Hackerearth):
There were 20 questions mostly based on C, C++, DS, Reasoning and a few from OS, OOPS,
DBMS etc and 2 coding questions.
The 2 coding questions were:
1) Find the maximum sum of lengths of non-overlapping contiguous subarrays with k as the
maximum element.
Ex: Array: {2,1,4,9,2,3,8,3,4} and k = 4
Ans: 5
{2,1,4} => Length = 3
{3,4} => Length = 2
So, 3 + 2 = 5 is the answer
2) You are given an array A where A[i] (1-based indexing) denotes the number of chocolates
corresponding to each station. When we move from station i to station i+1 we get A[i] –
A[i+1] chocolates for free. Note that if this number is negative, we lose that many chocolates.
We can only move from station i to station i+1 and that too if and only if we have non-
negative number of chocolates with us. Given that cost of one chocolate is Rs. P , our task
is to find the minimum cost incurred in reaching station n from the first station (station 1).
Ex: A: {1,2,3} and P = 10 Ans: 30
To reach station 1 from the starting station, we need to buy 1 chocolate.To reach station 2
form station 1, we get A[1] – A[2] = -1 chocolates i.e. we lose 1 chocolate. Hence, we need
to buy 1 chocolate.Similarly, we need to buy 1 chocolate to reach station 3 from station
2.Hence, total cost incurred = (1+1+1)*10 = 30.
Out of around 150 students, 26 were shortlisted for Round 2.
911
Chapter 382. Set 376 (On Campus for Internship)
-> In the 1st question those who used cin/cout instead of printf/scanf got TLE in 20% of
test cases.
->In the 2nd question not a single test case was passed on using int instead of long long int.
I wasted about 40 mins on this.
->Doing MCQ was important. Few students who solved both the coding question but didn’t
attempt the MCQs were not selected while some who could solve 80% of 1 question(8/10
test cases) and few MCQs were selected.
Round 2: FTF Interview (Around 30 mins):
First, the interviewer told me to introduce myself and then he asked me : Count
all nodes at distance k from a given node in a binary tree. It’s very similar to
https://www.geeksforgeeks.org/print-nodes-distance-k-given-node-binary-tree/ . Suddenly
he went out of the room and came after about 20 mins.By that time I came up with the
O(n) solution, I explained it to him with a pseudo code. Then, he asked me if I had any
questions for him.
Round 3: FTF Interview (Around 45 minutes):
First, the interviewer told me to introduce myself and then asked me the question asked in
the 1st round. Then, she asked me about threading.I told her that I haven’t studied JAVA
well. Thereafter she didn’t ask anything related to JAVA.
1 .https://www.geeksforgeeks.org/search-in-row-wise-and-column-wise-sorted-matrix/ I
started with an O(RlogC) ssolution,she told me to optimize it , after some time I finally
gave the O(R+C) solution.She asked me to write the code.
2. A stream of integers are coming you need to keep the track of minimum at any
time, which DS would you use? I told her that I’ll simply store the numbers in a
vector and keep a variable min and update min whenever required. Then she told me
what if you need to find Kth minimum. I told her to explain the question again , then
she asked https://www.geeksforgeeks.org/k-largestor-smallest-elements-in-an-array/. We
discussed various approach. She asked me to code the Max-heap approach(use of STL was
allowed).Then she asked me various questions about heap.
3. How to represent heap efficiently? I told her the array representation, then she asked
me to explain the one using pointers. After that, she asked me which one is better and
why? I listed various reasons one of which was that array is cache friendly, she asked me to
elaborate this.She also asked me few questions on cache.
4. She asked me to explain heap sort in detail. We discussed it for about 5 min covering
everything in detail. Code was not required.
5. https://www.geeksforgeeks.org/connect-n-ropes-minimum-cost/ . Initially my approach
was wrong, she showed a case where it failed . After some time i told her O(N*N) approach
which was correct, she asked me to optimize it and told me to think of some DS which i can
use.Finally, I came up with the solution using heap, she asked me to code it.
Finally, she asked if I had any questions for her. My experience of this round was very good,
the interviewer was very helpful and friendly.
Out of the 26 selected for the interviews, 13 were finally selected for internship.
912
Chapter 382. Set 376 (On Campus for Internship)
During my preparation geeksforgeeks, indeed, was a great help. Almost all questions asked
in the interview were from geeks. A big thank you to other geeks as well for sharing their
interview experiences as going through past experiences was the perfect way to end my
preparations.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-376-campus-internship/
913
Chapter 383
Amazon Interview Experience | Set 377 (On-campus for Full time) - GeeksforGeeks
Amazon visited my Campus few days back .Here is my interview experience.
There was 1 online round and 3 FTF and a bar raiser.
Online Round (conducted on Hacker Earth)
20 MCQ questions and 2 Coding Questions
MCQ question-each 1 mark(-0.25 mark for wrong answer)
Coding Questions- each 10 mark
1. Given a string you have to partition the string in such a manner that each part of
the partitioned string is a palindrome in itself and you have to count the number of such
partition.
For eg: given string NITIN
N ITI N
NITIN
NITIN
Output-3
2. You are given with a large paragraph and N words.
You have to find a min length subparagraph of the paragraph which contain all those N
words in any order. Here length of a paragraph is the count of words in the paragraph.
First Technical
1. https://www.geeksforgeeks.org/find-the-smallest-window-in-a-string-containing-all-characters-of-another-strin
2. https://www.geeksforgeeks.org/efficiently-implement-k-queues-single-array/
Second Technical
We have n machines in which n tasks can run, and we have common cooling time t(in cycles)
for all the machines.Certain conditions need to be followed –
914
Chapter 383. Set 377 (On-campus for Full time)
1. Task can run only on its assigned machine.Each task is assigned its own separate machine.
Eg.Task1 runs on Machine1. Task2 can run on machine2.Task3 on machine3.
2. Initially all machines are cool and tasks can run on them.
3. At a time,only 1 task can run on its assigned machine.No 2 tasks can run simultaneously
even on their assigned machines.
4. Machine needs to be cooled for the cooling time period t after its task’s run is over.
5.Each task takes 1 cycle to run and machine takes t cycles to cool.
We are given an array which contains the order in which tasks are going to run on the
machines. So we need to find out how much cycles in total it would take to run those tasks.
Eg.
n=3
int arr[] = {3 ,1, 2, 1, 2}
int t = 2(cooling time)
Output=6
Explanation-
In the start task 3 can run on third machine(T0)
Task 1 runs on first machine(T1)
Task2 on second machine(T2)
Now task 1 waits since cooling time is 2 (T3 gone in waiting)
Task 1 runs now(T4)
Task 2 runs on second machine as cooling time of second machine has passed (T5)
Total cycles consumed to run all tasks =6 cycles
. We are given two unsorted arrays, size can be different we need to swap two elements one
from first array and second from second array such that the sum of each individual array
becomes equal after swapping.
Eg
int a[] = {4, 3, 5}
int b[] = {9, 1, 6}
Output-{4, 6}
4 from array a and 6 from array b are swapped to get equal sum of each array as 14.
Third Technical
Few questions from my project.Then he asked me about structure of C program.
Page fault and swap space.
• What is Caching
• Implement LRU(Only logic was asked like which data structures you would use and
how) and then 2 coding questions
• Say you are given a tree and a target node, so we need to restructure the tree when
target node becomes the root.(node can have more than 2 child)Keep in mind all the
cases.
• Count Inversions in running stream of integers.(I gave answer using bst)
Bar Raiser-
Given initial capital W and n projects and the capital being used in each and the profit
915
Chapter 383. Set 377 (On-campus for Full time)
earned from each.You need to select k projects out of these n projects such that at the end
your capital is maximised.
Eg-
W=3
int capital[] = {9,2,3,1}
int profit[] = {13,5,2,7}
int k = 2
output- 13
Explanation- We choose project with capital 1 and new capital becomes(3+7-1=9)
now we choose project with capital 9 and gets profit of 13 so final capital becomes(9+13-
9=13)
I gave answer by initially sorting the array according to capital and then selecting those
projects which have capital required less than or equal to initial capital and insert them in
max heap, after extracting the top node decrease k and my capital would change and now
i can insert new projects from remaining in my max heap which have capital required less
than or equal to new capital and repeat this step till k becomes 0.
Verdict-SELECTED �
GEEKSFORGEEKS, indeed was a great help :D.
Tips-Don’t panic ..keep trying different approaches ..they will help you when you are
stuck..Try to do as many experiences from geeks.Do all the questions under Amazon tag
from geeksforgeeks.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-377-campus-full-time/
916
Chapter 384
Round 2: F2F
2 questions were given,
1st:- you have given an array of non-negative numbers and target sum, you to find minimum
length of subarray whose sum is larger than target
2nd:- you have given an array with repeating numbers, and a window k less than n, you
were suppose to find if there is any repeating element for and ith index, like { 1, 2, 3, 4, 5,
2, 5} and k=2, for i=4, it is true.
Round 3: F2F
4 questions were given,
1st:- find K random elements from N distinct elements such that probability of all remain
the same.
2nd:- HeapSort
3rd:- check whether two trees are mirror images of each other or not.
4th:- https://www.geeksforgeeks.org/word-ladder-length-of-shortest-chain-to-reach-a-target-word/
917
Chapter 384. Set 378 (On-Campus)
Round 4: F2F
1st:- what is pointer
2nd:- how recursion works and how its memory allocation happens.
3rd:- https://www.geeksforgeeks.org/given-sorted-dictionary-find-precedence-characters/
4th:- https://www.geeksforgeeks.org/word-ladder-length-of-shortest-chain-to-reach-a-target-word/
5th:- https://www.geeksforgeeks.org/maximum-sum-nodes-binary-tree-no-two-adjacent/
Round 5: F2F
1st:- https://www.geeksforgeeks.org/print-a-given-matrix-in-spiral-form/
2nd:- given an infinite binary stream, you are suppose to on every ith position that whether
the number formed till is divisible by 3 or not, for eg. 0 1 1 0 1 1…
outout :- yes, no, yes, yes, no, yes..
Tips:-
1) remain Honest with them.
2) tell your approach how you are solving the question.
3) tell them frankly if you do not know some subject, in my case i know only DS and
Algorithm and they did not mind it at all.
4) go through past interview experience on geeksforgeeks
Getting placed in amazon is like a dream come true!!
Thank you geeksforgeeks, for all this, it helped me alot, whatever i have done, i have done
it from geeksforgeeks only!!
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-378-campus/
918
Chapter 385
Input: 3
Output: 1
Input: 4
Output: 2
Question – 2: There are ‘n’ friends who bring gifts to a Halloween party and they exchange
their gifts and the array of the number of gifts each person receives is given to you. Check
if such an arrangement (array) is possible and if it’s possible then, given an arrangement of
the same.
Examples:
Input:
3
1 1 1
Output: 2 3 1
919
Chapter 385. Set 379 (On-Campus for Internship)
920
Chapter 385. Set 379 (On-Campus for Internship)
additional space.
The same method as in the 2nd round was employed here. I was asked to Pseudo-code the
solution and code it in a language of my choice (C, C++, Java). Then, he asked me if I was
comfortable with Operating Systems; I said ‘yes’. He started with Paging, Fragmentation,
Security, Job Processing, Types of OS. He covered almost all concepts of OS. The questions
were application based rather than direct topic related.
Finally, 4 people were shortlisted and were given the opportunity to work with Amazon.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-379-campus-internship/
921
Chapter 386
922
Chapter 386. Set 380 (On-Campus)
Ques 2) Imagine a land in a form of grid. There are enemies to the North of the land. And
soldiers to the West of the land. Soldiers in the West want to know if there are enemies to
the North. So they decide to place mirrors at a 45-degree angle in the grid land. If they
place a mirror at (i,j) then they can see the enemies in the jth column. Similarly, they will
put mirrors in other places in the grid to view the enemies in other columns. Now it is given
that some of the cells of the grid are rocky area and a mirror cannot be placed in those cells.
Example:
|
Walls | Enemies
__________|
_ _ R _
Soldiers _ _ _ _
R _ _ _
_ _ _ R
Solution:
|
Walls | Enemies
__________|
_ _ R _
Soldiers / _ _ _
R _ _ /
_ / _ R
regex: *aab?c
string: dbvaabcc
923
Chapter 386. Set 380 (On-Campus)
output: True
regex: *c*
string: ca
output: True
regex: ?c?
string: ca
output: Fasle
Example:
string: 1011001010011 // 7 1's and 6 0's
output: 0110001111100
924
Chapter 386. Set 380 (On-Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-380-campus/
925
Chapter 387
Round 1 :
1. Design doctor appointment System.
2. Given a piece of code in java, provide code review comments.
Round 2 :
1. Explain architecture of project in depth.
2. Given a fully connected graph with n nodes and corresponding values. One node can
interact with other node at a time, to replace/ignore/add its value to other node’s value.
Assuming this operation takes 1 unit of time, how much time would it take for all the nodes
to have value equal to sum of all the nodes.
Examples : Given a graph with values {1,2,3,4}, find total time it takes, such that all nodes
have value as 10.
Round 3 :
1. Given a sorted string, find number of occurrences of given character in string.
2. Given a chessboard, find minimum number of moves for a knight to reach from source
to destination.
Round 4 :
In depth discussion on all the projects mentioned in resume.
926
Chapter 387. Set 381 (For SDE2)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-381-sde2/
927
Chapter 388
Amazon Interview Experience | Set 382 (On-Campus for Full Time) - GeeksforGeeks
The Selection process started with an Online Coding round.
20 MCQ and 2 Coding Questions:
MCQs were from OOPs, OS, DBMS, Networking etc.
Coding Questions:
Q – Rotate the given Matrix by a factor k. Input is given as two integers n,m (row and
column of the matrix). Followed by n lines with m space separated integers as all the
elements of the matrix. Last line has an integer k.
Input:
3 3
1 23
4 56
7 89
2
Output:
741
852
963
Q – Given a string. Find all the palindromic partitions of the string. (Number of way the
string can be partitioned so that all the partitions are palindrome)
Input:
NITIN
OUTPUT:
3
928
Chapter 388. Set 382 (On-Campus for Full Time)
NITIN
N ITI N
NITIN
Face2Face (Interview)
Round 1:
He asked coding questions straight away –
Q- Add two numbers without using +,- operator, recursion or loop.
Try to think in terms of half adder.
Q- Postfix to prefix without using recursion.
Q- Given an array of numbers. What is the largest no possible by concatenating all the
numbers together.
Input:
5
21 30 1 9 98
Output:
99830211
Q – Write the heapify code.
Round 2:
Q – Level order traversal of a tree. Further he asked to optimise the code.
Q – Given a matrix. ‘0’ means empty room, ‘1’ means door, ‘-1’ means a wall. For every
cell as an empty room find the distance to the nearest door (One cannot go through a wall).
Input:
55
0 0 1 -1 1
0 -1 0 0 -1
0 0 -1 0 -1
1 -1 1 0 0
00000
Output:
2 1 0 -1 0
2 -1 1 2 -1
1 2 -1 2 -1
0 -1 0 1 2
12123
** The door would be replaced with 0 as the distance to the nearest door would be 0.
I started by a backtracking solution. But the guy didn’t know what it was. I gave many
more solutions and concluded with an O(N) bfs solution.
Guys answer straight. Do not answer very complex algorithms, even though they are correct.
Try to provide as brute-force solution as possible.
929
Chapter 388. Set 382 (On-Campus for Full Time)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-382-campus-full-time/
930
Chapter 389
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-383-campus-internship/
931
Chapter 390
932
Chapter 390. Set 384 (On-Campus for FTE)
Second question was find min cost path in matrix.I told him the approach using bfs then
finally solved it using recursion with memoization.Then he asked to write my approach on
paper.He was very impressed with my performance in this round.
Round3(Bar-raiser):
Time: 60 minutes
The interviewer was the manager and head of the panelist.He asked me to introduce my-
self,what is my favourite subject.He asked me which question i had solved that i found to
be hard and what were the problems that came while approaching that question.Then he
moved on to the questions.
One question was given a n-ary tree,for every kth level of the tree,print the kth node present
at that level on counting form left and if kth node is not available, then print the last node
at that level.I told him the obvious approach using level order traversal.He asked me to
write code for that covering all corner cases.
Another question was buy and sell stock only once.Then he changed the question to buying
and selling multiple times to maximize final profit.He kept on confusing me by modifying
the problem constraints.Then he finally accepted my solution and asked me to dry run on
that code.
Round4(Face-to-face):
Time: 1.5 hr
This round was mainly based on problem solving and various CS subjects like
OS,DBMS,OOP etc.He started the round by asking me to introduce about my project
which was an android app.He asked me about the core idea of the app, its layout etc.He
asked me about what i had used for storing various information in database and i told
him that i used mysql with mysql statements called from PHP script using url encoding
mechanism in java.He asked me about the difficulties that i faced during my project and
how i had tackled those problems.Then he moved on to the questions.
The statement of one question was similar to the mobile-keypad problem.But there was
slight variation that a dictionary of words was also given along with a number and i had
to find all words which are present in dictionary that can be obtained by pressing this
number.I told him the usual approach using backtracking.He asked me to optimize my
approach.He gave me hint that it could be done by using some spaces.Finally i came to
the optimized solution by mapping individual letters with digits from which they can be
generated by pressing the digit like pressing 2 can generate letters a,b or c so map a,b and
c with 2.Then iterate over every word present in dictionary to find if it is the possible
solution or not.
Second question was to find next higher element in an array for every element.I told him
the brute-force one of O(n^2) time complexity.He asked me to optimize that.I tried it
using BST but it was not passing all test cases.Then after some hints, i finally came to the
solution using stack.
He asked me to design a class for tic-toe game where size of board given is variable n.I
was asked to implement the member function findWin() by checking all rows,columns and
diagonals for all 1s or all 0s for any matrix size n.
He asked me questions based on OOP like abstract class,interface,their differences etc. and
in OS, he asked me about mutex,semaphore,their differences etc and describe the software
life-cycle in detail.Finally the round ended.
9 students went in the 4th round of which 5 were selected.I was one of them. �
933
Chapter 390. Set 384 (On-Campus for FTE)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-384-campus-fte/
934
Chapter 391
Amazon Interview Experience | Set 385 (On Campus for Internship) - GeeksforGeeks
Round-1:
Platform: Hackerearth
Time: 1.5 hrs
The first round was an online coding round and 20 MCQs. MCQs were from general com-
puter science topics like: data structures, algorithms, dbms, puzzles and some questions
based on languages C, C++.
Two coding questions were of 100 marks each and mostly based on implementation skills
like forming cumulative arrays from both ends of the array, etc.
Suggestion: Have a good command over c++ STL or Collection in Java.
MCQs – +1 correct answer and -0.5 negative marking.
13 people were shortlisted for the interview rounds.
Round-2
There were 2 questions.
First was a puzzle i.e. You are having n weights in a line eg: 12 13 2 1 6, a man is coming
with a basket from behind the first weight. He can’t read which weight he is picking as he
is illiterate and he can only keep 1 weight in the basket. But he can compare the current
weight with the weight in the basket, if it is less or greater or equal and by making some
decision he can swap the positions of the two. Initially the basket is empty. Moving from
one weight to another adjacent weight takes 1 unit time. The man needs to arrange the
weights in descending order in minimum time. And derive the formula for this minimum
time taken.
HINT: try first placing the smallest weight to the rightmost while moving right and then
placing the largest weight to the leftmost while moving left. Idea: see every time we are
decreasing the path length by 2 (1 from both sides ) by placing the smallest and largest at
the start and end respectively.
935
Chapter 391. Set 385 (On Campus for Internship)
Second was an algorithmic question : Trapping Rain Water can be found on geeksforgeeks.
Link: https://www.geeksforgeeks.org/trapping-rain-water/
Round-3
3 questions were asked in this interview round.
Suggestion: Try to write clean code with all corner cases handled.
Question-1: Interviewer asked me which data structure i liked the most. I said Segment
trees. So, I was instructed to write the build function for range sum query in an array of
integers.
Question-2: Find the maximum length of the subarray with sum zero in an array of
integers.
Subarray with sum zero : is formed when elements repeat in cumulative sum array and
maximum length
subarray can be obtained by maintaining first occurence of the element.
Question-3: Find LCA (lowest common ancestor) of two nodes in a binary tree.
https://www.geeksforgeeks.org/lowest-common-ancestor-binary-tree-set-1/
I thanks GeeksforGeeks for helping me in my preparations.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-385-campus-internship/
936
Chapter 392
Amazon Interview Experience | Set 386 (On Campus for Internship) - GeeksforGeeks
The first round was an online round. There were 2 coding questions and 20 MCQs. The
MCQs consisted of both aptitude questions as well as technical questions. The students who
did both the coding questions and half of the MCQs were chosen for the interview round.
25 students out of 200 students who gave the online round were selected.
The first round of interview was the elimination round. It was a technical round in which
the interviewer asked me 3 questions, I had to tell him my approach and code the solution
on paper. After all the students were done with the first round, 17 students were selected
for the second round of interview. This round was also a technical round, I was asked 3
questions and was told to code them on paper. The interviewer also went through my CV
and asked about my projects. He also asked me a few technical concepts based on OS and
C++ (after I told him I code in C++).
Finally, 11 students were selected for internship, including me �
The questions asked were of the following topics :
1. Bit manipulation (2 questions in interview and 1-2 mcqs in online test as well)
2. BST and Trees
3. OS, networking and output of C programs in online MCQs
4. The coding questions in the online test included a string question and a mathematical
question which used
concepts of permutations and combinations
A tip for interviews: If the interviewer asks a question which you don’t know, be frank with
him and tell him you don’t have knowledge about it. This is much better than blurting out
irrelevant answers.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-386-campus-internship/
937
Chapter 393
Amazon Interview Experience | Set 387 (On -Campus for Full Time) - GeeksforGeeks
Round – 1:
The first round had 20 Aptitude MCQs (20 min) and 15 Technical MCQs (15 min) with
+1 and -0.25 marking schemes. The MCQs covered topics the included – DSA, Operating
Systems, C, C++, Java basics. After this, there were 2 coding questions (45 min). Minimum
cut off was set for each section. One question was of the Game Theory and other was of
Dynamic Programming.
Questions in The Coding Round: –
Q1) Given two players A and B and some positive numbers in an array, each player will play
game by choosing a positive difference of two numbers such that the number don’t exist in
the array and place that number in the array. If he is unable to find such difference then he
looses. Each player will play optimally so as the other player is not able to find two numbers
such that there difference doesn’t exist in the array.
Q2) Given a string containing only lowercase alphabets, you have to convert it into a string
such that it contains all vowels by doing minimum number of operations. In one operation,
you could select a substring always starting from index 0, and move that substring up or
down (any number of times). Following examples are treated as 1 operation.
For Ex:- input-axzf
Let index chosen be 0 to 3and move it up by 2
Output-czbh
For Ex:- input-axze
Let index chosen be 0 to 2 and move it down by 2
Output-yvxe
12 students were selected from this round out of about 125.
Round – 2:
938
Chapter 393. Set 387 (On -Campus for Full Time)
My interview lasted for about 20 minutes. I was tested on basic concepts of DSA and OS in
this round. My interviewer was very good, he made me feel very comfortable before we got
to the actual process of the interview. Firstly, he asked for my introduction and then asked
me to write a basic C program on a given series pattern (very easy) followed by questions
on Paging, Page Faults and Stacks.
Q1) Write a code to print the nth element of the given series
1 1 2 4 8 16 32
Q2) What is paging? Why is it done? What are page faults? What are the techniques to
resolve page faults?
Q3) Implementation of stacks using arrays.
7 students were selected from this round out.
Round – 3:
This interview lasted for about half an hour. Interviewer asked me to get comfortable. He
asked me about the languages I was comfortable with and then, he asked me questions on
bitwise operator and then asked some puzzles (these were really very tricky). Then he had
asked me questions on linked list and asked me to make my solution more and more efficient
(reducing complexity) followed by questions use of maps (STL in C++). Then he asked my
how a different site gets loaded into my web browser whenever I search for any of these sites.
Q1) Given a number you have to make it last 4 bits 0 in just a single line code.
Q2) Given array of integers you have to find 3 no’s such that sum of two makes the other
in minimum time complexity.
Q3) What is the difference between JAVA and C++?
Q4) What is PASS BY VALUE and PASS BY REFERENCE in JAVA and code for the
same on the paper.
You can practice some important questions on bitwise operators on https://www.
geeksforgeeks.org/bitwise-algorithms/
Also, while preparing for interviews you must also practice some puzzles on https:
//www.geeksforgeeks.org/puzzles/
3 students were selected from this round out.
Round – 4:
This interview lasted for about half an hour. As I had mentioned Java in one of my strong
subjects so he started form the basics of JAVA like what was the purpose and need for invent-
ing this language. Then he asked me to write a simple program just checking my practice on
implementing JAVA and some question of C too. Then he gave me some interesting puzzles
like https://sbjoshi.wordpress.com/2008/06/04/puzzle-burning-ropes/ was one of them.
Q1) What is the difference between malloc and calloc function in C?
Q2) What are static blocks in java?
Q3) Can main method be overloaded in JAVA? Why or Why Not?
Q4) How Is JAVA platform independent?
Q5) Is JVM platform dependent or independent? Why or Why Not?
939
Chapter 393. Set 387 (On -Campus for Full Time)
Only 1 student was selected from this round for internship at the Hyderabad Office.
The interview experience was quite good and they focused on all the core computer science
subjects. Geeks for geeks was a lot of help to me as it helped me in my placement preparation
and provided almost all content that was necessary for placement preparation.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-387-campus-internship/
940
Chapter 394
Amazon Interview Experience | Set 388 (On -Campus for Full Time) - GeeksforGeeks
Round 1: Online coding test – 90 minutes (HackerEarth)
It had 2 coding questions and 20 MCQs.
Q1: Knapsack variation(you can choose an item any number of times)
Q2: Given a 2D array consisting of 0’s, 1’s and 2’s. 1 denotes a fresh apple, 2 denotes a
rotten apple and 0 denotes absence of an apple at that position.
Each rotten apple takes 1 day to make it’s neighbors(8, given a fresh apple is already there)
rotten as well. Calculate the number of days when all the apples will be rotten.
If not, then print the number of apples which will never get rotten.
MCQs included some output based questions in C (5), time complexity (2), data structues
(10), OS(2), Java based output question(1) etc.
Round 2 (F2F1)
The interviewer was very chilled and asked me to introduce myself, then he asked me to
explain any of my projects. He then asked me two questions:
Q1: Given a special binary tree, find the height of the tree.
Speciality: each leaf is connnected to the next leaf(left to right) in a circular doubly linkedlist
fashion.
fashion. Let’s say the 2 consequtive leaves are A and B, so, A->right = B and B->left = A.
The leftmost leaf’s left points to the right
most leaf and the right most leaf’s right points to the left most leaf.
Expected time complexity = O(n), space complexity = O(1).
Q2: Flip maximum k bits to find the maximize the number of consequtive 1’s in a binary
array.
Expected time complexity = O(n), space complexity = O(1).
Round 2 (F2F2)
He started with an description of my projects and then he asked me several questions,
majorly:
941
Chapter 394. Set 388 (On -Campus for Full Time)
Q1: Next permutation of a given string(can contain duplicates). (Write complete code
including swap, reverse etc).
Q2: Find the mirror the a tree in which each node can have any number of children. (Write
complete code)
Q3: Boundary order traversal.
Q4: Check if the given 2 nodes are cousins or not.
Q5: Check wheather a given tree is a summation tree or not. (Any node’s value = sum of
all it’s children’s value).
Round 3 (F2F3)
She started with an description of my projects and then he asked me several questions,
majorly:
Q1: Difference between recursion and iteration(slightly long discussion).
Q2: Difference between array, linkedlist and trees.
Q3: Discussion on all O(n logn) sorting algorithms.
Q4: Sort an array consisting of 0, 1, and 2’s only in one pass.
Q5: Given 2 arrays which denote the elements to be inserted in two separate binary search
trees. Find wheather the two binary search
trees will be same or not, without actually constructing the tree.
Eg: 2 3 1
2 1 3
Ans = Yes.
Eg. 1 2 3
3 2 1
Ans = No.
942
Chapter 394. Set 388 (On -Campus for Full Time)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-388-campus-full-time/
943
Chapter 395
Amazon Interview Experience | Set 389 (On -Campus for Full Time) - GeeksforGeeks
Online Coding Round:
Time: 1.5 hr
Questions Format: 20 MCQs + 2 Coding Questions
MCQs were based on Data Structures, Operating systems etc.
Coding Questions:
1)Minimum time required to rot all oranges
2)Unbounded Knapsack (Repetition of items allowed)
Around 25 students were selected from the coding round and were called for further interview
rounds.
Round 1(Face-to-face):
Time: 45 minutes
The interviewer was very cool.He asked me to introduce myself and a brief introduction of
the projects that I have done.Then she moved on to the data structures part.
1) Find height of a special binary tree whose leaf nodes are connected
2) Maximum sum such that no two elements are adjacent
I was supposed to write the functions in the language of my choosing which take all the
input as parameters and return the answer. After the round was done, he insisted on me
taking a cookie �
Round 2(Face-to-face):
Time: 1.5 hours
The interviewer was very cool and asked me about how my previous round went.After that,
we immediately moved onto data structures part.
1) Minimum number of bracket reversals needed to make an expression balanced
944
Chapter 395. Set 389 (On -Campus for Full Time)
2) He asked me a question in which I have a 2D array and at every index, either there is a
soldier or a mine, I was supposed to find the minimum distance of every soldier from any of
the mines, I told him that this type of qs was already asked in the online round, after that
he asked me another qs, it was – Dynamic Programming | (Matrix Chain Multiplication)
3) Given a binary tree, how do you remove all the half nodes?
4) He asked me to implement all the standard properties of the heap that are “insert”,
“removal”, “deletion” and “update” in an array.
Round 3(Face-to-Face):
Time: 60 minutes
The interviewer asked me to introduce myself, after that he asked me questions regarding
OS, DBMS, and CN. we moved onto questions after that. After that, I was asked to
explain one of my projects to explain in complete details and also about the problems I
faced during the project. Then we moved onto qs.
1) Convert a given tree to its Sum Tree.
2) Convert an arbitrary Binary Tree to a tree that holds Children Sum Property
3) Reverse a Linked List in groups of given size
4) What is the time complexity of binary search, prove it mathematically.
All the students who qualified the round were taken for a semester long internship. Some
of us were given a chance to convert our semester long intern to a full-time job through
another round.
945
Chapter 395. Set 389 (On -Campus for Full Time)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-389-campus-full-time/
946
Chapter 396
Round 1:
Problem 1: Given a binary search tree, find the k th smallest element.
Problem 2: Given a matrix which is sorted both row wise and column wise, search for an
element.
Round 2:
Problem 1: Given a linked list, find and remove all the loops.
Problem 2: Construct a minimum spanning tree from a given weighted graph. While
solving this I made use of certain “set” functions. As I didn’t know syntax of these
operations in C++, wherever I had to make use of set functions I wrote a “sudo” function
call. So after writing the code for the question, she asked me to implement the set functions
947
Chapter 396. Set 390 (On-Campus)
Round 3:
He didn’t give me any problems. The questions were mostly based on an SQL based project
that I had done, and on my internship.
Round 4:
Given a number, find the next higher number which is a palindrome. Example: if given
number is 99 next highest palindromic number is 101, if given number is 72 next highest
palindromic number is 77.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-390-campus/
948
Chapter 397
949
Chapter 397. Set 392 (For SDE 2)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-392-sde-2/
950
Chapter 398
Amazon Interview Experience | Set 392 (On Campus for Internship) - GeeksforGeeks
Online Coding Round:
The first round was an online round. There were 2 coding questions (no penalty for
wrong submission) and 20 Multiple Choice Questions(with negative marking). We
were given 90 minutes to solve them.
MCQs were based on Data Structures, OS, CN, C outputs, OOP etc.
The two coding questions were:
1. Given a string you have to partition it in such a way that each part of the partitioned
string is a palindrome in itself and you have to count the number of such partitions.
Input: NITIN
Output: 3
Explaination: The 3 possible partitions are N | ITI | N, N | I | T | I | N, NITIN
2. You are given a large paragraph and N words. You have to find a minimum length
subparagraph of the paragraph which contains all those N words in any order. Here, the
length of a paragraph is the count of words in the paragraph.
951
Chapter 398. Set 392 (On Campus for Internship)
2. Given a binary tree, if parent is 0, then left child is 0 and right child is 1. if parent is 1,
then left child is 1 and right child is 0. Root of the tree is 0. Find the kth node value which
is present at Nth level.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-392-campus-internship/
952
Chapter 399
Amazon Interview Experience | Set 393 (On Campus For Internship) - GeeksforGeeks
Online Coding Round:-
There were 2 coding questions and 20 MCQ’s.
1. Given an array find all the triplets having their sum of elements less than a given number
k.
2. Find The N-th Magic Number.
1st Interview Round(Face To Face) :-
The interviewer was very friendly. He went through my CV and asked me if I had any
project. To which I replied no and told him that I am currently on a project and later I
gave him a brief explanation of it. For those who didn’t do any project don’t worry much.
He asked me 2 questions
1) Generating All the Possible Subsets(Subset Iteration).
2) Slight Modification of BFS on a grid. I told him my approach and he was satisfied wth
that.
After I told my approach for the 2nd question he told me to write a Pseudo Code for BFS
in a graph.
He was the best interviewer I faced till now.
The interview lasted for around 45 mins.
Other people were given questions like
1) The middle element in a linked list.
2) Merge Sort in a Double Linked List.
3) Merge Two Sorted Arrays.
4) Given A Binary Tree, For every Leaf Node print sum of the values from the root node to
the leaf node.
5) Quick Sort
6) LCA in Binary Tree and Binary Search Tree.
953
Chapter 399. Set 393 (On Campus For Internship)
I told him that the above code actually fails. He asked me why it fails. I answered him
this way.The array a is actually in the function Append and once you leave the function the
scope of this array ends. He asked me how to do it then. I had no idea. Later he told me
that we have to allocate memory for the array using malloc.Later on he explained me how
it works using heap memory.
For my friends, he asked the question in a different way(Merge Two Sorted Arrays).
Thanks to GeeksForGeeks For my interview preparation.
All Practice Problems for Amazon !
954
Chapter 399. Set 393 (On Campus For Internship)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-393-campus-internship/
955
Chapter 400
956
Chapter 400. Set 394 (On-Campus Full Time)
Round 3:
Here, the interviewer first introduces herself and then asked about me, then told me to
explain any one of my projects. After that she asked me few basic computer science questions
followed be 2 DS/Algo problems.
1. How are recursion and iteration handled by the compiler.
2. How differently are a linked list and array stored in memory.
3. Difference between multiprocessing and multithreading.
4. All normal forms in DBMS.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-394-campus-full-time/
957
Chapter 401
Input : 6 10
Output :2
6 -> 110 (2 set bits, 2 is prime)
10->1010 (2 set bits , 2 is prime)
so 6,10 are even numbers having prime number of set bits
(Use the optimized way to check prime by creating a array
of prime numbers and trying to divide the setbit count
to check if it is prime or not).
Qs2: Given n lines a land can be split into many areas of different measure(say b). You are
provided with a constant K . You have to find whether it is possible to use K areas from
the B areas
Input : 2 4
Output : True
Think of a circle whenever a circle is split by
958
Chapter 401. Set 395 (On-campus for Internship)
Round 2:
It was a group fly round . Me and my friend sat in the same room and were asked to code
the following:
QS 1: https://www.geeksforgeeks.org/rearrange-characters-string-no-two-adjacent/
But I dint use a stack I used hashmap to find the occurrences of the characters. Created a
character array traversed the map with an iterator.Filled the character array with elements
in odd positions then after all odd positions are filled I filled in the even positions. Used a
validate function to check whether the newly generated string has no adjacent characters
repeating. If false print no string can be formed else return the string.
Qs 2: Given a tree and a element K . Find the root-leaf path with a sum equalling K and
delete the path.
Total of 10 were shortlisted.
Next was the final round. It was F2F round .
Round 3:
The interviewer asked me give a brief introduction about me.
Then he moved on to shoot coding questions at me.
QS1:
Find the intersection elements in 2 unsorted arrays.
Input: 5 4 1 3 2
12 3 15 1 7
Output: 3 1
QS2: This was an interesting question . Given Air tickets to different cities in the
form of a pair of cities where one denotes the source and another tells the destination.Our
job is to return a linkedlist indicating the way the travelling should travel in order to cover
all the cities.(Linkedlist wasnt mentioned by the interviewer).
959
Chapter 401. Set 395 (On-campus for Internship)
Soln: Put them in a hashmap. Now find the occurrences of all cities. In this we can notice
that the source and destination occurs only once in the tickets.Cross check with the original
pair list to find which one is the source and which one is the destination. Then with the
help of a separate comparator function push the pairs into a new hashmap in such a way
that the source of one pair must have been the destination of the previous pair).Then
traverse the new hashmap to create a linked list then return it.
The interviewer will also help you if you ask for any approach (but don’t ask them
for more help.) But if the interviewer intentionally gives a clue then code as he wishes as
it is one of their way to test you whether you can adapt to anything approach and code.
My personal advice: Be confident, Keep your communication skill high , use geeks-
forgeeks website to learn linked list ,Trees, STL and DP then solve all Company specific
questions.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-395-campus-internship/
960
Chapter 402
961
Chapter 402. Set 396 (For SDE-2)
Design Recommendation system. How will you generate generate recommendations for
millions of users. DB Schema, How will you improve latency? if the user is searching a
item, when will you show next recommendations. How will you update, latency basically
and consistency.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-396-sde-2/
962
Chapter 403
1. Given a string. Find all the palindromic partitions of the string. (Number of way the
string can be partitioned so that all the partitions are palindrome)
2. You are given with a large paragraph and N words.You have to find a min length
subparagraph of the paragraph which contain all those N words in any order.
Round 1 (35-mins):
The interviewer started with the most common questions “Tell me about yourself” , in which
I explained my projects , my achievements and my strengths. I was asked 2 questions from
ds and algo in this round.
1. Find all the hero and super hero in an array. Hero – Elements which are greater than
all the elements on its right side. Super Hero – Elements which are greater than all
the elements on its left and right side (Largest Element of the array which should only
occur once). Expected Complexity – O(1) space and O(n) time in single traversal.
Input: {1,6,5,4,7,8,4,3,2,1}
Output: Heroes : 8 4 3 2 1
Super Heroes : 8
2. https://www.geeksforgeeks.org/find-the-smallest-window-in-a-string-containing-all-
characters-of-another-string/
Round 2 (60-mins):
963
Chapter 403. Set 397 (On-Campus)
I was asked to introduce myself asked about my strengths and my weakness. Like last round
I was asked 2 questions on data structures and algorithms.
Discussions on projects for 15-20 minutes.
1. Find Maximum number possible by doing at-most K adjacent swaps. Expected Time
Complexity – n*K and space complexity – O(1)
2. Find the closest pair to a given sum in an unsorted array. Approaches – Brute force,
Sorting , Ceil and floor using BST.
3. Memory Allocation in C++. How to allocate double memory in c++. Couldn’t
Explain this.
1. https://www.geeksforgeeks.org/design-a-stack-that-supports-getmin-in-o1-time-and-
o1-extra-space/
1. What is caching ?
964
Chapter 403. Set 397 (On-Campus)
1. https://www.geeksforgeeks.org/minimum-time-required-so-that-all-oranges-become-
rotten/
2. https://www.geeksforgeeks.org/fix-two-swapped-nodes-of-bst/
3. https://www.geeksforgeeks.org/bottom-view-binary-tree/
Verdict : Selected �
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-397-campus/
965
Chapter 404
966
Chapter 404. Set 398 (On-Campus)
3. Write a program and approach for Minimum no. of iterations to pass information to
all nodes in the tree. https://www.geeksforgeeks.org/minimum-iterations-pass-information-
nodes-tree/. I was very close to the solution and he was very impressed by my approach of
recursion. He interrupted me between the solution and asked further questions.
4. Approach for K smallest element in array. https://www.geeksforgeeks.org/k-largestor-
smallest-elements-in-an-array/. I presented 3 solutions and heap solution then he asked me
about heap and its time and space complexity.
5. Approach for Largest Rectangle in Histogram. https://www.geeksforgeeks.org/largest-
rectangular-area-in-a-histogram-set-1/. I presented two solutions naïve solution and stack
based solution.
Round 3:
In this round, the interviewer asked me about my resume project and deep discussion on
my projects.
1. Write a program to find position of an element in a sorted array of infinite numbers.
https://www.geeksforgeeks.org/find-position-element-sorted-array-infinite-numbers/. I pre-
sented 3 solutions in most optimized way.
2. Question on computer science fundamentals. Detailed explanation of virtual memory,
paging page faults etc.
3. Write a program for Minimum Number of Platforms Required for a Railway/Bus Station.
https://www.geeksforgeeks.org/minimum-number-platforms-required-railwaybus-station/.
4. Write a program to count set bit of a number. https://www.geeksforgeeks.org/count-
set-bits-in-an-integer/. I presented 3 solutions and he was impressed by my last solution of
using concept of last bit set using formula x&-x.
5. Last question similar to the concept of this question sort numbers stored in different
machines. https://www.geeksforgeeks.org/sort-numbers-stored-on-different-machines/.
Round 4:
This round was based on designing problems.
Min Cash flow among friends. https://www.geeksforgeeks.org/minimize-cash-flow-among-
given-set-friends-borrowed-money/. I solved by n^2 and nlogn complexity. In nlogn I used
the concept of heap.
In each round interviewers were giving test cases to run on the programs and expecting very
neat and clean code.
So I would recommend to have experience of competitive coding for depth knowledge of
code and then follow geeksforgeeks. It has all the problems.
Before 2-3 of campus recruitment I would recommend to solve all problems of interviewbit
with the help of geeksforgeeks.
All Practice Problems for Amazon !
967
Chapter 404. Set 398 (On-Campus)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-398-campus/
968
Chapter 405
Amazon Interview Experience | 399 (On Campus for full time) - GeeksforGeeks
Amazon came to my campus in the last week of July, 2017.
The online round was hosted on HackerEarth platform.
It had 2 coding questions and 20 MCQs.
Q1. Given an unsorted array A, find the largest value of i-j such that A[i]>A[j].
Q2. Given an unsorted array A and a number k, find the maximum sum sub string in the
array such that its sum is divisible by k.
MCQs:
1 mark each and 0.25 negative mark.
Few MCQs were based on data Structures, algorithms, oops and operating Systems, 1 or 2
from logical reasoning, networking and DBMS each.
Every interview round started with the cliche “tell me about yourself” and ended with “do
you have any questions”.
Round 1:
Design Question : Given a log file with product id and corresponding customer id for the
products searched on amazon, you need to find the most viewed product at the end of the
day. If a product is viewed multiple times by a single customer its view count is increased
only by 1. Number of products are very large so sorting, heap or hashing of product Ids is
not feasible.
Solution- Use Trie data structure. After 10 minutes of discussion I could come up this.
Production level code for insert and search in a trie was required.
What if k max viewed products were required.
During my discussion he also asked me to write a hashing function.
Round 2:
969
Chapter 405. Set 399 (On Campus for full time)
1. Dfs of a graph.
Dfs of a n array tree. (Code was required)
2. Given a string s and a file with each word on a separate line, find all the words in the
file which are anagrams of the string s. The interviewer asked me tell all the possible
solutions irrespective of the complexity. This continued for 10 min.
3. Given a m*n matrix find number of paths from (0,0) to (m-1,n-1), at every block we
either move 1 step down or 1 step right.
4. Print all paths for the above questions. A dp solution was required.
Round 3
1. Given a n*n matrix with distinct elements from from 1 to n^2, find minimum number
of bombs required to destroy all cells of the matrix. If we bomb a cell with value i, a
cell with value i-1 if 4 adjacent to it will also be destroyed. (Code was required)
What if the the numbers were not unique.
2. Find majority element in an unsorted array.
Find majority element in sorted array. (logN solution was required)
3. Print the elements of a tree diagonally.
4. Find shortest distance between two nodes of a tree where every node also has a pointer
to its parent node and we can also directly jump from a node a to node b, where b is
the mirror image of a and a and b belong to the two sub trees rooted at the root of
the given tree. The mirror image may or may not exist.
5. Find the time required to pass information from root to all the nodes of the tree. Link
The interviewer then asked me which other non coding subject do I like. I said os.
So he asked me several basic questions on OS.
What is-
1. os
2. thrashing
3. bdady anamoly
4. page fault
5. threading
6. multi processing
7. difference between threading and multiprocessing
8. scheduling algorithms
Round 4
The famous Amazon’s Bar Raiser Round
My internship experiences.
Detail discussion about my summer internship project.
What is your favorite algorithm and why.
Toughest thing you did in college.
What are some leadership principles you learnt during your summer internship.
What was the non technical thing you learnt at your internship.
This was a telephonic round and went on for 34 minutes.
970
Chapter 405. Set 399 (On Campus for full time)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-399-campus-full-time/
971
Chapter 406
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-400-sde-2/
972
Chapter 407
Amazon Interview Experience | 401 (3+Years Experience for SDE II) - GeeksforGeeks
Recently I was interviewed for Amazon SDE II for Amazon Pay Team. Below are the
Questions :
.
.
Round 1 : (Written : Pen & Paper) (3 Questions)
Q1) Given a 1D Array. Return True if there exists an element where a[i]+a[j] = 0 && i!=j.
Reference : https://www.geeksforgeeks.org/find-a-pair-with-the-given-difference/
Input : arr = {2,-3,4,1,-6,-4,1}
Output : True
Input : arr = {2,3,4,1,-6,4,1}
Output : False
Q2) Related to Buy and Sell of stock and gain maximum profit. Only 1 unit to buy or sell
at a time.
Reference : https://www.geeksforgeeks.org/stock-buy-sell/
Q3) Given a Tree (it was a BST), replace the data of all nodes which have data >= the
node’s data.
Exactly Same problem : https://www.geeksforgeeks.org/add-greater-values-every-node-given-bst/
(Even the example was same from above link ;))
.
.
Round 2 : DS and Algo (F2F) (3 Questions)
Q1) Program for n’th node from the end of a Linked List
Exactly Same problem : https://www.geeksforgeeks.org/nth-node-from-the-end-of-a-linked-list/
Q2) Print min & max (both) of all subarray of size k
Reference : https://www.geeksforgeeks.org/sliding-window-maximum-maximum-of-all-subarrays-of-size-k/
973
Chapter 407. Set 401 (3+Years Experience for SDE II)
Note : The reference link is just for min or max. Here we need both min and max in one
program.
Q3) Find the k most frequent words from a file (or a stream of input)
Exactly Same problem : https://www.geeksforgeeks.org/find-the-k-most-frequent-words-from-a-file/
.
.
Result : I was eliminated due to some basic mistakes I did (in Q3), which I just realized
after leaving the Interview room. It was a nice experience.
.
.
I would also like to share few more Questions those were asked to other candidates over
there :
Q1) Design Debugger (Asked to almost everyone in 2nd Round)
Q2) Design Uber App
Q3) https://www.geeksforgeeks.org/print-nodes-distance-k-given-node-binary-tree/
Q4) https://www.geeksforgeeks.org/connect-nodes-at-same-level/
Q5) https://www.geeksforgeeks.org/minimum-number-of-jumps-to-reach-end-of-a-given-array/
.
.
The Interviewers were very friendly and helpful. They will help you whenever you get stuck
(with Hints), but they will also check how much grab you have on basics.
.
.
Thank You!!!… Hope this will help the aspiring candidates.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-3years-experience-sde-ii/
974
Chapter 408
Source
https://www.geeksforgeeks.org/amazon-interview-experience-402-experienced-sde-2/
975
Chapter 409
Amazon Interview Experience | Set 403 (On Campus for Full Time) - GeeksforGeeks
Codding round (90 min):
20 objectives from DS, OS, DBMS, Networking and 2 coding questions:
i. https://www.hackerrank.com/contests/dakshonline/challenges/yule-ball
ii. https://www.hackerearth.com/practice/data-structures/arrays/1-d/practice-problems/
algorithm/i-demand-trial-by-combat-13/
ROUND I:
1. Given a binary string (e.g. 01, 101, 011), in each iteration 0 becomes 01 and 1 becomes
10, find kth character in the string after nth iteration
simple approach, time complexity, express time complexity in terms of n only
efficient approach, explanation, time complexity
2. Given n ropes of different lengths, connect them into one rope. cost to connect two ropes
is equal to sum of their lengths. connect the ropes in minimum cost :
https://practice.geeksforgeeks.org/problems/minimum-cost-of-ropes/0
3. When and why merge sort is preferred over quicksort – time/space complexity
ROUND II:
1. Project discussion
2. Make binary tree symmetric – which all cases are possible, which traversal is used and
why
3. Make half of the linked list reverse (iterative, recursive) and some questions from linked
list
4. Recursion, data structure that is used in recursion
5. C++ string, overloading of + operator in string class
ROUND III:
1. Design a data structure to show most frequently purchased item to a customer, show
items that are frequently purchased in a given time span
2. Priority_queue, map/unordered_map, sliding window concept
976
Chapter 409. Set 403 (On Campus for Full Time)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-403-campus-full-time/
977
Chapter 410
Input : NITIN
Output : 3
Input : AAa
Output : 4
978
Chapter 410. Set 404 (On-Campus Internship)
Input : 40
Output : 10 12 21 23 32 34
I gave a brute force solution first and then he asked me to optimize it. We had a long
discussion then he asked me to code the solution.
Only 6 students got selected for the next round.
Round 3( Technical Interview )
The interviewer started with the most common questions “Tell me about yourself” , in which
I explained my projects , my achievements and my strengths.
The round started with long discussions on following Questions of Operating Systems.
1. What is deadlock? and situation where you have faced deadlock.
2. Scheduling Algorithms.
3. Code LRU Cache
4. Banker’s Algorithm.
5. Paging , Segmentation etc.
6. How compiler compiles the interlinked libraries.( Using Topological Sort ) and asked me
to code for the same.
One Coding was asked in last
Trapping Rain Water
In Last interviewer winded up the interview with “Any questions for me?”
Verdict : Selected
Only 3 students were offered internship
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-404-campus-internship/
979
Chapter 411
980
Chapter 411. Set 405 (SDE-II)
Interviewer: Order of insertion is not maintained in HashMap. Write code to maintain the
order of insertion.
Me: We can directly use LinkedHashMap in Java. This Data Structure suffices the require-
ment.
Interviewer: How does LinkedHashMap work internally?
Me: Explained the internals of LinkedHashMap. Elaborated how it maintains doubly linked
list to maintain the order of insertion on top of HashMap mechanism. This is helpful to
know internals of Java Data Structures
Question 3:
Have you ever faced conflict in your team? For example, if your team member is trying
to implement sub optimal solution and you don’t want him/her to do so. How have you
handled this situation?
Question 4:
Largest Sum Contiguous Subarray
Discussion included naive approach, solution using maintaining single variable and complex-
ity of each.
For questions 1 and 4, interviewer asked me to write production ready code on paper.
Expectation included to cover all the corner cases and input check and all.
Round 3: Technical Round (Duration: 1 hour)
Interviewer: Tell me Data Structure of your choice. I’ll ask questions on that.
Me: Can we have questions on Linked List?
Question 1:
This interviewer also started with Hashmap. Again we had all the discussion which I had
in Round 3 Question 2.
Design your own Data Structure for LinkedHashmap and write production ready code for
insertion of elements.
Question 2:
Why Amazon?
Question 3:
Imagine we have a big box open at top and some small boxes are put inside it. The one of
the side view of the box be like.
981
Chapter 411. Set 405 (SDE-II)
Think of final positions of the all boxes (Final elements in array) and design algorithm to
solve the problem. We can just discuss the algorithm. No need to write code.
We discussed about final positions of boxes on paper and finally I figured out that it is
nothing but a sorting of array. I answered to have to go with Merge sort. Interviewer asked
me why not Quick sort? We discussed about complexity of both the algorithms and issues
occurring due to selection of pivot in Quick sort.
Round 4: Design Round (Hiring Manager) (Duration: 1 hour)
Question 1:
Interviewer asked me to choose area from which he can ask design question.
1. Online Gaming
2. Inventory Management
3. Taxi services like Ola, Uber.
I chose second option.
Interviewer asked me to Design automated parking lot
We started with classes to be used. Discussed database structure. Many other aspects like
what if I own many parking lots. What if only one vehicle is coming at a time? What if I
have multiple lanes to enter parking. What if many vehicles are coming at a given time?
We discussed synchronization of thread, thread pooling, thread queuing.
Question 2:
Tell me about your current work.
Round 5: Behavioral Round, Bar raiser (Taken by two highly experienced peo-
ple) (Duration: 1 hour)
Question 1:
Introduce yourself.
Question 2:
Discussions about my previous project with previous employer.
Question 3:
1. Discussions about my current work with current employer. They asked me complete in
and out about my current project. I answered the question with inclusion of many design
patterns which are implemented in my project.
2. Tell us something which you have contributed to project. I had implemented some IPC
on the top of available framework. They asked me how IPC work internally? How will you
implement it if infrastructure is not provided. I explained the OS concepts behind IPC.
3. If trade off needs to be done on quality of product being released or to follow release date,
which one will you choose.
4. How do you handle conflict in your team?
Question 4:
Do you know furniture? If yes, design one. (Too vague question)
We discussed more about requirements as I was not clear about it at all. Came up with
some classes of furniture.
Write a SQL query to retrieve furniture from database whose dimensions(Width,Height,Length)
match with the given dimension. Initially, I wrote a strict SQL query to match exact
dimension. Then, interviewer asked me how Google search will work if you search for
982
Chapter 411. Set 405 (SDE-II)
furniture with above dimension. I answered that it gives other furniture with similar
dimension as well. I modified my earlier query to have something similar to Google result.
Result: I got selected.
Note:
1. Each interview started with brief introduction of the interviewer and mine.
2. Each interviewer was friendly and supportive. There was no pressure, tension at the
time interview. It was like a normal technical discussion. Interviewer gave hints to find the
answers whenever required.
3. We discussed about interviewer’s work at Amazon in each round.
4. After every round, I asked for area of improvement in me. Like it can be anything,
what should I read more, which skill should I develop. (It is not something about interview
feedback, as I know that it is always kept confidential from interviewee).
5. Don’t start solving problem as soon as interviewer gives you one. Ask questions if you
are not clear about the requirement.
6. Round 5 was meant for checking interviewee’s behavior in different situation.
7. Most of the times, interviewer is not expecting the correct answer but is evaluating your
thought process. Keep talking whatever is going on in your mind. Most important prepare
your resume very well.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-405sde-ii/
983
Chapter 412
https://www.geeksforgeeks.org/rearrange-a-given-linked-list-in-place/
question 2: Given an array of integers, print pairs(positive value and negative value of
the number) that exists in the array
984
Chapter 412. Set 406 (Off-Campus Internship)
1. deadlocks
2. mutex vs semaphores
3. ultithreading vs multiprocessing
4. TCP protocol
5. DNS
6. 3-way handshake in TCP
7. discussion on OSI layer
8. ACID properties
9. models in DBMS(ER, network….)
10. discussion on ER model
1. given row wise and column wise 2d matrix, find k minimum elements
https://www.geeksforgeeks.org/kth-smallest-element-in-a-row-wise-and-column-wise-sorted-2d-array-set-1/
2. given an array and a window size and window moves from left to right till the rightmost
side of window hits the other side of array, print max element in the window for
each step in the process
https://www.geeksforgeeks.org/sliding-window-maximum-maximum-of-all-subarrays-of-size-k/
this round happened for two hours
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-406-off-campus-internship/
985
Chapter 413
1. https://www.geeksforgeeks.org/write-an-efficient-c-function-to-convert-a-tree-into-its-mirror-tree/
2. https://www.geeksforgeeks.org/print-binary-tree-vertical-order
986
Chapter 413. Set 407 (Internship)
Round 3: This round was conducted only for those students for whom they were doubtful.
fortunately i was selected in 2nd round itself.
Interviewers were friendly. They helped us giving hints wherever we got stuck.
My advice is be confident. don’t give up, if you are stuck anywhere. Tell them atleast a
brute force approach and they will give you hints to optimize it. Don’t be scared, practice
questions from geeksforgeeks, almost all of them were asked from geeksforgeeks collection.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-407-internship/
987
Chapter 414
988
Chapter 414. Set 408 (Internship)
Then he asked me some questions from OS i.e. internal fragmentation vs external fragmen-
tation to which I replied “I don’t remember the topic but please let me try” then I got
correct answer to one question and wrong to second one. Then he asked about process life
cycle.
Then he asked that if I have any questions and then he asked ” why Amazon?” That was
it.
We were said to wait and luckily I was selected.
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-408-internship/
989
Chapter 415
Input of the function is two arrays filled with 24 hours of data and value/item of array is
tuple having direction and time. find following things,
Finding no 1 is easy.
Only issue is with 2,3 as we don’t have any unit of distance given anywhere. I asked him he
told that’s a problem ?
This what we can do without distance we can at-least find the minimum and maximum
time for sensor A and B just traversing an array but after that finding a distance that’s still
a mystery to me ? in last few minutes he told me take a guess and do it but no enough
time.
Round 2:
Build an UBER platform no code discussion about how will you do it,
990
Chapter 415. Set 409 (For SDE-I)
3. Find nearest driver ? (We can filter all drivers based on location)
4. What if two cities are merged like Redmond and Bellevue then other car might be
close but in second city where city filter want work ?
5. How do you scale same app to other countries (like china) ?
6. One you find the nearest driver how do pick them ? (I said ratings)
7. What would do consider as good ratings ?
8. Once you have 10 driver with 4.8 ratings how will you send the request ?
9. What will you do if all 10 drivers receives and accepts 10 request simultaneously ?
Round 3:
Build Eclipse IDE. Told me to write down class diagram of all components.
Round 4:
https://www.geeksforgeeks.org/find-duplicates-in-on-time-and-constant-extra-space/
No offer by the way.
In SDE-I two designing questions. I didn’t expected that. Even though i have done some
designing over past 2 years but never attempted problem as big as an IDE.
Hope this helps and PEACE.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-409-sde/
991
Chapter 416
Input : NITIN
Output : 3
Input : AAa
Output : 4
https://www.geeksforgeeks.org/given-a-string-print-all-possible-palindromic-partition/
2. You are given with a large paragraph and N words.You have to find a min length sub-
paragraph of the paragraph which contain all those N words in any order.(Case Insensitive)
Only 32 students got selected for Personal Interviews Rounds.
992
Chapter 416. Set 410 (On-Campus Internship)
Firstly I gave him the approach using queues. Then he asked me to optimize the code
for space complexity of O(1). Then I gave him the approach using recursion and a long in
depth discussion followed on it. Then he asked me to write the code.
Question 2: Given the no. of stairs as the input and a person can step forward either 1 or
2 or 3 steps at a time. Find the total no of possible ways person can climb the stairs.
Input : 3
Output: 4
Question 3: Given a 1-D array having equal no even and odd numbers. Arrange the numbers
in such a way that all the even no get the even index and odd no get the odd index. Required
space complexity and time complexity was O(1).
Only six students were selected for the next round.
Round 3(Technical Interview II):
This round was similar to the previous rounds. Firstly the Interviewer introduced himself
and then asked me to introduce yourself.
He asked me 2 questions related to Data Structures.
Question 1: Print all the continuous sub-arrays where the sum of the sub-array becomes
zero. Required space complexity was O(n).
Question 2: Given a string containing parenthesis. Find the total no of reversal of parenthe-
sis to make the given output as balanced one. This question followed a detailed discussion
and interviewer gave me different no of inputs to test the code.
After the coding questions. he asked me some basic questions related to Operating Systems
like Deadlocks and Semaphores.
At last 3 students got the internship offer from Amazon.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-410-campus-internship/
993
Chapter 417
994
Chapter 417. Set 411 (SDE-1)
String: bababbcac
The pattern is, the words in the dictionary should be present in the string in same order and
the letter taken by one word should not be the part of other dictionary word. We should
find whether all the dictionary words can be formed or not in the given string.
Answer:
Let me index the string bababbcac – (1,2,3,4,5,6,7,8,9)
1st word in dictionary – abc follows 457
2nd word in dictionary – bca follows 268
2nd word in dictionary – bba follows 134
Question 2:
It was from dynamic programming in string stuff
Source
https://www.geeksforgeeks.org/amazon-interview-experience-411-sde-1/
995
Chapter 418
Input: arr=(2,-3,4,1,-6,-4,1}
Output: True
Input: arr={2,3,4,1,-6,4,1}
Output: False
Round 2:
Regular Expression parser like finite state automata
Example: a*, aab*, abcb*c, ba*.c*, a.b, a*b etc etc and edge cases
Design a ranking system. We have an infinite supply of words ending with ‘.’ We need to
implement a reader program that ranks words on the basis of certain criteria
996
Chapter 418. Set 412 (SDE II)
Ranking System criteria : rank the words on the basis of occurrence, for example
Output : This:2, is:2, my:2… highest rank (sorted asc or desc based on provided flag)
Design it completely and scalable Ranking System.
Design a debugger
Round 3:
• Explain your greatest accomplished project and what big you achieved? – Details of
flow and architecture
• Find a longest palindrome String
• Design Amazon Cart System. (HLD and LLD ) Discussion on solution.
Round 4:
• Given a Binary Tree, Replace every node with its larger Same as sum tree
• Print min & max (both) of all sub array of size k
Reference : https://www.geeksforgeeks.org/sliding-window-maximum-maximum-of-all-subarrays-of-size-k/
• Given an integer array and find first k largest elements. Focus was on complexity of
the code
• Given an integer array and an integer value X, return three elements in that array
such that sum of them equals to X.
This was the last round for the day as team had to return to Bangalore. HR shortlisted me
along with other two candidates. Due to Diwali they were falling short of staff for managerial
rounds, So it look a month for other two rounds which happened in their Gurgaon office on
VC
Round 5:
Bar Raiser: (Duration : 1.15 hours)
Round 6:
Hiring Manager : (Duration : 1.15 hours)
997
Chapter 418. Set 412 (SDE II)
Behavioral Questions –
• Did you encounter any conflicts with colleague or manager and how did you solve
them
• Have you ever delivered more than expectations
• Have you ever completed project before deadline
• Have you have handled a client/customer efficiently and what did you
• Did you ever design a system/process
• What were the most critical projects you have worked on
• How did you handle a critical situation or helped a colleague
• Tell me about a time when you had to work on a project with unclear responsibilities
• Have you mentored someone? What were challenges you faced and how did you resolve
• What important technical decisions did you take and how did it help your team?
• Why Amazon
I recommend GeeksForGeeks for technical coding rounds, educative.io for design and http:
//kraftshala.com/how-to-raise-the-bar-in-the-amazon-interview/ for behavioral.
Pretty much covers all the details. They announced result after a week and I was selected �
All Practice Problems for Amazon !
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-412-sde-ii/
998
Chapter 419
999
Chapter 419. Set 413 (SDET-1 On-Campus Internship)
Round 2:
https://www.geeksforgeeks.org/validity-of-a-given-tic-tac-toe-board-configuration/
This was on paper round. I have heard there is another easier solution using magic square.
8 were selected from this round.
Round 3:
Technical Interview Round 1
The interview started with the most common questions “Tell me about yourself” and
“Projects/Internship”. Then there were few theory questions like what is binary tree? What
is binary search tree? Then 2 coding questions.
1. https://www.geeksforgeeks.org/level-order-tree-traversal/
2. https://www.geeksforgeeks.org/find-next-greater-number-set-digits/
Instead of digits, it was string of alphabets. There was a bug in my code. Interviewer gave
me a test case and asked me to test it. Changed the approach and solved it by sorting. He
asked which sorting and why? First I said merge sort because of nlogn complexity. Then I
said since range is small(1-26), we can use count sort. He asked if we really need sorting?
Then I said that reversing the second part was sufficient because it was in descending order.
Round 4:
1000
Chapter 419. Set 413 (SDET-1 On-Campus Internship)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-413-sdet-1-campus-internship/
1001
Chapter 420
1002
Chapter 420. Set 414 (For SDET-1)
The interviewer was pleased with my solution and asked me to code the solution completely.
After a few days I had 2 face to face rounds.
Round 2:Testing and Automation round(1 hr)
The interviewer just started out by asking whether I had previous knowledge about testing
and testing environments to which I replied no.Then we discussed about the types of testing
and the different phases and the testing procedures that are associated with it. Then she
asked me two simple test case generation questions.
1. Generate all possible test cases for an add function which takes two strings as input
and returns an integer which is the sum of the two numbers that are given as string
input.
I gave around 10 test cases for the question as it was pretty much straight forward. And I
coded a few by using JUnit testing which is really simple.
2. Given a open file module in an editor what are the possible scenarios in which the open
file module might give errors.
I gave a list of cases which we clearly discussed about the ins and outs of each one.
This round was quite easy since I prepared the testing part the previous day.
Round 3:Data Structures and Algorithms Round(1hr 15 mins)
Two guys interviewed me this round. We just started out with a formal introduction.Then
they asked me two questions.
Given a n*n chessboard and a knight which is placed at any one corner, Generate all possible
paths following which the knight can cover all the squares.
I started with a approach using BFS. But there was a flaw in my approach which was that
the knight would not escape from a cell if all the possible points the knight can go from that
given point was explored previously.
Then I gave a solution using Backtracking.
Start with a corner.For each and every possible point the knight can reach make recursive
calls to those using a simple for loop.Once the count reaches n*n(Example in a 8*8 chess-
board,if the count is 64),Print out the traversed path that can be easily maintained in an
array. This solves the flaw in my previous approach as we are able to go back to the other
possibilty if a dead path is reached.
The interviewer was happy with my approach and asked me to code the solution. I coded
it and then we moved on to the next question.
2. Given a linked list find the intersection point of two linked lists which converge at a
common point.
I gave a brute force O(n^2) approach at first then optimised it to O(n) time and O(n)
Space approach.Then I finally gave a O(n) time O(1) space solution by finding the absolute
1003
Chapter 420. Set 414 (For SDET-1)
difference of the lengths of the two lists.Then they asked me to code the solution which was
pretty much straight forward.
After this I had the final two rounds on October 31st.
Round 4:Hiring Manager Round(1hr)
The interviewer asked me to brief about myself.We then settled down on my project for the
first few minutes and then the interviewer asked about the interviews that I had attended
earlier and how the process went through. Then he started asking about testing and the
use of testing corresponding to some given scenarios. After a few minutes of discussion he
asked two questions regarding data structures.
1. Given an array of integers print the pairs that add upto a given sum.
I gave a O(nlogn) approach at first to find the pairs and print them. The approach was to
sort the array and keep two indexes(at each end) left and right and find whether pairs that
add up to the given sum and print them until the left and right pointers cross.
Then he asked me if I can optimize it further. I gave a O(n) approach using hashing.I
maintained a hashset of integers. Put the first number in the hashset, start from the second
element and for each number in the array check whether (Given sum – Current element) is
present in the hashset. If so print the pair.
2. Given a binary tree print the bottom view of it.
After a few minutes of thinking I came up with an approach by using the horizontal distance
of the nodes from the root. We have to keep note of the last node at a particular horizontal
distance while traversing using level order traversal. I used a Hashtable to store the last
visited node at each horizontal distance.
This approach uses O(n) time and O(n) space.
He then asked a puzzle.
In a room of 30 people,find the unique number of handshakes given a condition that each
one in the room should have shaken hands with everyone.
I just used a simple logic. In a room of 2 people,there is only one unique hand shake(First
person has 1 unique handshake whereas the second one has none). If we consider three
people,n = 3 (A,B,C)
A has two unique handshakes B,C.(n-1 handshakes)
B has 1 unique handshake C.(n-2 handshakes)
C doesn’t have any unique handshake.
total number of handshakes = n-1 + n-2 = 2n-3 = 3.(which is the sum of first two natu-
ral numbers)
Similarly for n persons the unique handshakes would be the sum of first n-1 natural numbers.
For n = 30, Total number of unique handshakes is 29*30/2 = 29*15 = 435.
That’s a wrap. He was happy with the way I approached the solution.
1004
Chapter 420. Set 414 (For SDET-1)
He asked if I had any questions for him. I asked about the culture and working environment
at amazon.
Round 5:Bar Raiser Round(1hr)
Two members entered the room and introduced themselves and we just started out with my
introduction and my project.
They asked me how many rounds I had before the current one. They just asked a few
questions about testing at first.Then they asked two coding questions.
I just instantly started with a brute force solution by finding the inorder traversal of the
tree.Then sort the array and find the kth largest in the sorted array which is the (n-k)th
element from the start index of the array,where n is the total number of nodes in the tree.This
uses O(nlogn) time and O(n) space.
They asked me to optimize it further.
I gave a O(nlogn) time and O(1) space solution by converting the binary tree into doubly
linked list and then finding the kth largest in a doubly linked list which can be done in
O(nlogn) time.
But there is a better solution for this which I couldn’t think of during the interview.Just
construct a minheap of k elements,Insert elements into the heap by traversing the tree using
any traversal.
If the heap root element is smaller than the current node in the tree remove the root element
from heap and insert the new element to the heap. At last after the complete traversal of
the tree the kth largest element will be at the root of the heap.This uses O(nlogk) time and
O(k) space.
But they were happy with my approach as they said me to optimise it either by space or
time. I gave a constant space approach so they were satisfied.
2.Given a directed graph, find whether there exists a cycle or not.If it does exist print it.
I gave a solution using BFS. I put a node in the queue and then added all possible nodes
that can be reached from the current node. While we traverse the nodes we just mark the
node as visited in the hashmap in order to avoid indefinite looping between nodes. They
were satisfied with my approach.
Finally they asked how HashMap is implemented and how it works(especially how hashcode
and index are computed). I designed my own hash function and explained the way get and
put functions work in a hashmap. They were happy with my explanation and then they
asked how would you modify your hash function in case of collision and discussed in brief
about collision handling techniques.
They asked if I had any questions for them. I just asked the same question I asked the
previous round.
P.S: For each question we have to write the code clearly. Don’t just dive straight into the
coding part, explain your approach clearly. Be confident and they don’t want the optimized
1005
Chapter 420. Set 414 (For SDET-1)
solution for the question,they see how the candidate approaches the question.
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-414-sdet-1/
1006
Chapter 421
1007
Chapter 421. Set 415 (For SDE-2)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-415-sde-2/
1008
Chapter 422
Amazon interview Experience | Set 416 (On Campus for Internship) - GeeksforGeeks
Coding Round
There were 2 coding questions (10 marks each) and 20 MCQ’s from various core concepts (
OS,DS,Algorithms,DB,C language etc ).
1009
Chapter 422. Set 416 (On Campus for Internship)
Interview Round 2
The interviewer asked me about my previous interview and its questions.
Later he gave me 2 coding questions.
Question 1 : Given an array of integers with the property that arr[j] – arr[j-1] is either
1,0,-1 and a search value, provide an efficient search mechanism.
Answer : The naive approach is to perform linear search which is O(n). Then I thought
along lines of binary search but, as such we cannot divide and recur because of the array’s
property.
After some time, I came up with a method which starts with the first element and compares
each element with the search value and increment its location by absolute difference of the
current value and search key.
This is a worst case O(n) algorithm, but does far better than linear search in generic case.
Question 2 : Given an array of integers(duplicates allowed) return if it is a set of contiguous
integers or not?
Input: 5,2,3,6,4,4,6,6 Output: Yes (as it is from set of [2,3,4,5,6])
Answer : First, I gave him a hashing based approach. Initially, make a hash of all the
elements and then pick the first element and increment in 1’s till you find a value not
present in the hash. Similarly decrement in 1’s from the first value and get the count. If
the count equals hash size it is true else it is false.
It is O(n) time complexity and O(n) space-complexity.
He asked me to improve the space complexity to O(1).
I tried a lot but didn’t get to solution. Then, he simplified the problem by giving hints and
making it a duplication detection problem in a array without using any additional space
provided the numbers are in the range [ 0,length_of_array -1 ].
This can be done by accessing element at index j as arr[j]%n and as make arr[arr[i]] =
arr[arr[i]] + n*arr[i]. So if at any stage arr[j]/n is > 1 implies we have visited it earlier. He
was satisfied with this solution.
DS Questions
1. Give use cases when you will prefer Hash table instead of BST and vice-versa?
2. What happens in case of duplicate insertions in Hash table and BST. What is its effect
on the complexity of search?
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-416-campus-internship/
1010
Chapter 423
1. Distance between two given nodes in a binary tree. I was asked to write the optimal
approach for the this.
https://www.geeksforgeeks.org/find-distance-between-two-nodes-of-a-binary-tree/
2. A group of people are seated in a circular table. After a while , each members takes
a chit and writes his name along with the next person name (anticlock wise.) . If
such chits are given , re draw the the table. A optimal approach was expected. eg. A
– B – C- D – E – A
chits will be written as A-B
B-C
C-D etc
3. Same questions as above . if each member takes a chit and writes his neighbors name
. re draw the table.
Round 2:
1. Given a Binary tree with root(R) , a node(N) and distance (k). find all the nodes at
k distance from N. Optimal solution was expected.
https://www.geeksforgeeks.org/print-nodes-distance-k-given-node-binary-tree/
2. Given a linked with next pointer and random pointer. Clone the linked List.
Round 3:
1011
Chapter 423. Set 417 (For SDE- 2)
1. Given a string of arrays “cat,dog,god,act”. Print all the anagrams which comes first
in list.
eg. output is cat ,act,dog and god. Means all the similar anagrams should be printed
together and the next print should be the one which comes earlier in the list.
https://www.geeksforgeeks.org/given-a-sequence-of-words-print-all-anagrams-together/
hint : Trie approach was expected here.
2. Given a stream of input Integers, at any time get the median of those numbers.
Round 4:
1. Design Bookmyshow : HLD, LLD and different race conditions discussion and scala-
bility discussions.
Round 5:
1. Given a input String and a patterns string. return all the start index of the input
string whenever the anagrams of the pattern match with input string. eg.
in : abcbaabba
pat : ab
output : index 0
index 3
index 5
index 7
2. Design RedBus kind of app : HLD, LLD and different race conditions discussion and
scalability discussions.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-417-sde-2/
1012
Chapter 424
1013
Chapter 424. Set 418 (For SDE 2)
LRU implementation
Round 4:
This round was completely design round (LLD and HLD)
Design Debugger then in between he moved to design Meeting scheduler
In last 10 minute he asked me to give HLD of Clock Room
Round 5:
This was taken by some senior developer,
He asked few question related to previous work, its challenges then moved to technical
question
Finding missing number in array, i gave XOR approach then he deep dived into how XOR
work
given a tree having unique nodes and given n and k value, find n node and then print all
nodes having distance of k from nth node in both the direction
Then again some behavioral question,
Why amazon?
Why leaving current org?
This type of questions.
These all rounds happen on the same day, then i was asked to leave for the day and wait
till next week for getting the feedback and next steps if any.
After 1 week, i got mail stating that, we would like to proceed further and scheduled my
bar raiser round.
Round 6 (BR):
It was telephonic discussion,
Interviewer judged me on Amazon leadership principles,
And i believe i just slips on one of the principle but overall he was satisfied with my responses.
And he asked me to explain HLD for Automatic Parking System.
This interview stretched for long since there was some network connectivity issue with my
cell network,
In last he asked me to explain just the approach of solving a technical problem,
Exact question i don’t remember but it was related to merging k sorted array.
Round 7 (HM):
Nearly next week this interview was scheduled since Hiring mangers were not available due
to their busy schedule,
Majority of the time this interview was around behavioral questions and Amazon leadership
principles.
1014
Chapter 424. Set 418 (For SDE 2)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-418-sde-2/
1015
Chapter 425
Set 419
Round 2:
a) Sort an array arr = {1, 0, 0, 0, 1, 0, 1, 1, 1, 1} with o(n) complexity. It is also called
segregation of an array.
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-419/
1016
Chapter 426
1017
Chapter 426. Set 420 (For QAE)
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-420-qae/
1018
Chapter 427
1019
Chapter 427. Set 421 (For Internship)
Question 3-: A variant of Binary tree traversal. I was given a tree and the output was given
had to identify the type of traversal and then code it out.
It was right_subtree->left_subtree->root
Question 4-: Stock buy sell to maximize profit problem (https://www.geeksforgeeks.org/
stock-buy-sell/)
Followed by some random discussion about amazon and its products.
In general interviewers were friendly and ready to help whenever i got stuck.
Cheers!
All Practice Problems for Amazon !
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-421-internship/
1020
Chapter 428
Round 2:
On site Interview:
Round 3:
1. Design VLC.
Round 3:
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
1021
Chapter 428. Set 422 (For SDE II)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-422-sde-ii/
1022
Chapter 429
Amazon Interview Experience | Set 423 (For Cloud Support Associate) - GeeksforGeeks
Round 1: The first round was an elimination round, i.e.the online test.The test comprised
for 3 sections-the general aptitude and English(easy to moderate difficulty), then came the
technical section which mostly focused on OS and CN mcqs(can be solved well if one has
really good knowledge of both subjects), and the final section was of programming(2 ques,
around 30 min-but the questions weren’t difficult).
Round 2: The next round comprised of 2 technical interviews.Questions were asked from
OS, CN, troubleshooting of network etc(in-depth concepts). Also a few programming
questions were asked to some candidates.These 2 rounds and the managerial round were
more of elimination rounds.
Round 3: The final round comprised of 2 more interviews-managerial and HR.The manage-
rial interview questions were related to project work, various difficulties faced and various
scenario/situation-type questions.The HR interview was also about life experiences and sce-
narios.The trick is to be completely honest and have a solid justification for all the answers.
The interviewers were quite co-operative and understanding.It was really a great experience.
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-423-cloud-support-associate/
1023
Chapter 430
1024
Chapter 430. Set 424 (For SDE 2)
1) where a person can pay to another person and money directly gets deposited into other
person’s bank account.
2) A person can also send reminder to another person for owning money.
Round 2: Design Round (1.5 Hrs)
1) Detailed discussion on project and design of it, how will you scale your project to support
n number of users. Focus was on scalability & distributed design.
2) Design a job scheduler, scalability, fault tolerance, high availability, how scheduler picks
up job,
how will you take care where one job can run for 30 min and one for 30 hour, how will you
distribute jobs on servers.
Based on frequency & time how will you execute them ?
How will you notify back the user about start/stop or completion of a job ?
How will your system know if a job is killed / terminated due to unknown reasons ?
Round 3: Coding Round (1.5 Hrs)
Given array -> {5, 1, 3, 2, 8}
and a Linked List where elements will be from the array but can also be duplicated.
3 -> 2 -> 5 -> 8 -> 5 -> 2 -> 1 -> X
Sort the linked list in the order, elements are appearing in the array. O(n) complexity was
expected. Complete running code on paper was expected. All boundary condition checks
were expected.
Round 4: Coding Round (1.5 Hrs)
Given a n-ary tree, basically a graph but connected and doesn’t contain cycle.
every edge is given a weight, identify all paths from all vertex to all vertex & then sum of
all paths.
Give final result as sum of all paths.
Ex:
10 20
A——-B——–E
30/ \40 \ 50
/ \ \
C D F
Here all paths and their sum are as follows: Ans should be sum of all of them.
A-B = 10
A-E = (10+20)
A-F = (10+50)
A-C = 30
A-D = 40
B-E = 20
B-F = 50
B-C = (10+30)
B-D = (10+40)
C-D = (30+40)
C-E = (30+10+20)
C-F = (30+10+50)
D-E = (40+10+20)
1025
Chapter 430. Set 424 (For SDE 2)
D-F = (40+10+50)
E-F = (20+50)
First write the data structure to solve this problem, then efficient algorithm, then complete
working code on paper.
Overall it was a positive experience, recruiter kept me informed about the progress and
about next rounds. First four rounds went well but I wasn’t able to solve 5th round problem,
and was eliminated after then.
Thanks a lot to geeks for geeks for having such a great amount of collection to practice on.
Advise:
• Please do prepare for behaviour questions as well. Have one or two example ready
for all the questions. Most of them are available here : http://kraftshala.com/how-to-
raise-the-bar-in-the-amazon-interview/
• Prepare for design rounds seriously, they look for scalability, high availability & dis-
tributed system architecture in your design.
• For coding prepare your basics and have them thorough, practice using pen & paper
for writing code.
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-424-sde-2/
1026
Chapter 431
Set 425
To best of me i have given answer to all the three programs(little doubtful with 2nd one).
No Selected. �
For first question my approach was:
1027
Chapter 431. Set 425
}
}
else {
count++;
}
}
System.out.println("Start = " + start + "End = " + end);
}
}
Explanation: Solved in O(n) time complexity. In order to improve the complexity we can
use divide and conquer strategy(Modified version of Jump Search or interpolation Search)
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-425/
1028
Chapter 432
1029
Chapter 432. Set 426 (For SDE-1)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-426-sde-1/
1030
Chapter 433
1031
Chapter 433. Set 427 (SDE-2)
After clearing these rounds, I was invited for on-site interview to Chennai for
further rounds.
Round 4 (Design):
After this the HR informed me that the feedback of my design round was quite
good and also gave me suggestions to perform well in rest of the rounds.
Round 5 (Bar raiser):
Few questions to evaluate me on Amazon’s leadership principles. I can’t remember them
all �
1032
Chapter 433. Set 427 (SDE-2)
• Asked me to return the 2 corresponding nodes (at the end of diameter) instead of the
diameter.
Note: In problem solving rounds, you’re supposed to write a working code in any language
of your choice, handling all the corner cases.
Finally got an offer after 3 days!! � All the best!! (y)
All Practice Problems for Amazon !!
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-sde-2/
1033
Chapter 434
• A brief introduction
• Clone a Binary Tree with Random Pointers
• Write a program to calculate pow(x, n)
• A brief introduction
• Program for Best Fit algorithm in Memory Management
• Design a deck of card (only the model classes)
• NoSQL vs a SQL database (when to choose which)
• A brief introduction
• Almost 15 minute discussion about what Customer Returns Team in Amazon does
• A very detailed description of technical challenge faced (it includes HLD, LLD and
the solution offered)
• Design Promo Code API taking Amazon’s customer traffic into picture (HLD and
LLD was discussed – including in memory databases)
• Which areas of yours would you like to improve upon? (Both technical and non-
technical)
1034
Chapter 434. Set 428 (For SDE-2)
• A brief introduction
• Variation of Topological Sorting : You have been given a set of inter-dependent tasks
along with the time taken to execute them. We have more number of parallel processors
available than the number of tasks given. There could be multiple starting tasks. There
could also be cyclic dependencies. Calculate the minimum time required to complete
all the task. Complete end to end production ready code was expected.
• A brief introduction
• Responsibilities in the current company
• Why do you want to change your company
• Anything which makes me different from somebody else (technical and non-technical)
• Any project which I’m proud of. What’s so special about that particular project.
• Arrange given numbers to form the biggest number
• What difference does having a docker makes if compared to directly deploying appli-
cations on the VMs?
• When did you felt that you are not liking the status quo of a workflow? Any past
experiences.
• Discussions about a mongoDB cluster vs an elasticsearch cluster (from my projects)
Round 2 to 6 were done in Amazon Hyderabad campus. All interviews were back to back.
It started from 11 AM to 5:30 PM with just half an hour lunch break. Before I could even
1035
Chapter 434. Set 428 (For SDE-2)
step out after completing one round, other interviewers would already be waiting outside.
Interviewers were very helping, but only if your are thinking in the right direction. HR also
was very supportive. He was coming and motivating me after every round. Some advices
here
• If your couldn’t solve a problem, don’t carry forward negative thoughts into next
round. It will affect the next round as well.
• If your have prepared well, importance of keeping calm and cool should not be ignored.
Trust me, you won’t survive the stress of whole day otherwise.
• All the codes you would be asked to write down on paper and designs on the white
boards, so practise accordingly.
• Prepare for the design interviews well, they play a big role for SDE 2.
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-428-experienced/
1036
Chapter 435
1. There is a university with certain sets of courses. You can take a course in any semester
but you need to finish its prereq course (if prereq is given for a course) before that.
Design the whole university structure and suggest the Algo. He then changed the
question bit, if you can take up a course and its pre req in the same semester how will
your code change. https://www.geeksforgeeks.org/topological-sorting/
1. Convert a roman number into an integer number. He provided me with a set of rules.
2. Explain your Project
3. Most challenging thing in your project.
4. Do you review code. what all code changes you have suggested till now.
5. Any big enhancement suggested by you to make your code better.
It was not a coding question only. He expected me to write a Heap interface and using
that implement min heap or max heap. And also write the heapify code
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
1037
Chapter 435. Set 429 (For SDE 2)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-429-sde-2/
1038
Chapter 436
1. Given an array and an operation -> foo(index, value), the value can be either 1 or -1,
if foo(index, value) is called, it will add ‘value’ to all elements from index till end of
the array, find minimum number of operation to make all array elements 0.
2. Don’t remember completely, but it was something like finding a deadlock in a BST.
Round 2:
1. https://www.geeksforgeeks.org/trapping-rain-water/
2. https://www.geeksforgeeks.org/longest-possible-chunked-palindrome/
Round 3:
Design round:
Round 4:
Managerial round, lot of project and Amazon’s leadership principle related questions.
Round 5:
Bar Raiser: Lot of behavioral and leadership principle questions, then asked a design ques-
tion, design a load balancer’s algorithm so that it redirects the traffic between three services
s1, s2, s3 by 50%, 30% and 20%. further clause added to handle various clients calling to
specific services.
1039
Chapter 436. Set 430 (For SDE2)
Tips for the interview: Good hands on towards problem solving and algorithm, HLD
and LLD, prepare well for Amazon’s leadership principles.
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-430-sde2/
1040
Chapter 437
1041
Chapter 437. Set 431 (For SDE2)
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-431-sde2/
1042
Chapter 438
There was an online codding test on Hackerearth. Two questions were asked. I don’t
remember them now.
Round 2:
After two weeks they scheduled a telephonic round.
Question 1: Given a matrix of ‘0’ and ‘1’, find the largest Iceland (i.e area of ‘1’s)
https://leetcode.com/problems/max-area-of-island/description/
Question 2. Design a data structure with constant time for insert, delete, search and ge-
tRandom.
https://www.geeksforgeeks.org/design-a-data-structure-that-supports-insert-delete-search-and-getrandom-in-consta
I had given solutions for the both.
Round 3 :
This was onsite interview at Hyderabad.
First he asked about my past projects and challenges faced. He then asked if I had designed
anything on top of current a system.
Next a technical question was given;
Given an array of integers and a window size ‘k’, find first negative number for each possible
window in the array.
https://www.geeksforgeeks.org/first-negative-integer-every-window-size-k/
1043
Chapter 438. Set 432 (For SDE-2)
I first gave him a two queue approach(was not optimal), he told to code it on paper. After
I wrote the code, he asked to optimize it further. Finally after few iterations, I gave him an
optimal two pointer approach.
My suggestion here is; do not hurry to present your solution to interviewer, first try to
come-up with best optimal solution. For SDE-2 positions they expect optimal solution at
the very first place from you.
Round 4 :
This was all project and HLD related round.
There were two interviewers. The first introduced themselves and told about what their
group does at amazon.
He then asked about my role at previous company and past projects I did in brief. Then
asked if I have done something like adding new functionality or suggested some improvement
for the project that was not asked by customer or manager.
He then asked me to draw HLD for meeting calendar system. Then there was discussion on
various issues on it like scalability, what database should be used; SQL-NoSQL, concurrency
etc.
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-432-sde-2/
1044
Chapter 439
1. Given n sized stairs and we can take 2 or 3 steps at a time. How many ways are
there to climb the stairs? Question was pretty straight forward. I was able to answer
quickly. https://www.geeksforgeeks.org/count-ways-reach-nth-stair/
2. Given an array with adjacent numbers differing by an absolute value of 1. A number
is given and we have to search it (They do not expect the trivial linear search O(n) ).
I was able to figure out the algorithm for it pretty quickly. https://www.geeksforgeeks.
org/search-an-element-in-an-array-where-difference-between-adjacent-elements-is-1/
3. Given a time hh:mm format. We have the find out the bigger angle between
the hour and minute hands. I took some time to figure out the formula for
it and had to show the derivation of the formula to the interviewer on the
screen. https://www.geeksforgeeks.org/calculate-angle-hour-hand-minute-hand/
4. This was a testing related question. The amazon site (some specific functionality) was
working very well one day before but because of something, that functionality is slow
and customers are complaining. I had to tell how will I debug this.
The interviewer was pretty impressed by my coding skills but not so much with my testing
skill (I guess :P). Anyways, I got the call for my next rounds. There were four of them at
Hyderabad itself. Amazon took care of all the travelling and stay (Awesome nah :D)
Round 2: (Software development Manager 1 ) : 45 mins
Asked questions like:
1045
Chapter 439. Set 432 (SDET Off – Campus)
1. Design a framework for the testing the Cart service of Amazon. We can Add, delete
and update the elements in the cart.
2. Write unit test cases to test an add Address page in Amazon.
3. What advice as an SDET will I give to a developer and what precautions will I take.
Well, Guess what, I was not selected for the role. They were quite impressed by my coding
skills and not so much with my testing skills. Fair enough !
Tips for Aspirants: Study geeks well (mostly the Data structures part and in
Algo mostly the DP part). Go through other interview experience of Amazon
. https://www.geeksforgeeks.org/amazon-interview-preparation/ For testing, I don’t
have much idea.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-432-sdet-off-campus/
1046
Chapter 440
1047
Chapter 440. Set 433 (SDE 2 for Experienced)
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-433-sde-2-for-experienced/
1048
Chapter 441
1. Given a binary tree, print all the boundary nodes in an anti-clockwise direction starting
from the root.
Problem Link: https://www.geeksforgeeks.org/boundary-traversal-of-binary-tree/
2. Deletion Operation on Doubly Linklist, Cover all the test Case.
Round 3: Telephonic
1. There were two Data Structure & Algorithms problems, I only remember one question.
2. Merge Overlapping Intervals – Solved using a stack.
Problem Link:https://www.geeksforgeeks.org/merging-intervals/
Round 4: Face to Face
1049
Chapter 441. Set 434 (For SDE-2)
In short hiring manager covered some Amazon Leadership principles such as customer ob-
session, disagree and commit, dive deep, develop and hire the best etc.
1. Design BookMyshow website backend and discussion on HLD, LLD and DB schema.
There were discussions on various issues like Scalability, What database should be
used; SQL-NoSQL, Concurrency etc.
2. Have you done something in the team that improved team productivity?
3. Have you delivered something in tight deadline?
4. Why are you looking for a change?
Overall the technical bar was good and if one practices DS/Algo questions along with
HLD/LLD and some concepts of System Designs, then he/she can easily crack the rounds.
Some tips/links.
1050
Chapter 441. Set 434 (For SDE-2)
After this long amazing process, I got a call from HR after seven days stated that “Hi,
Congratulations you are selected and cleared all the rounds and we are happy to offer you
SDE-2 position”.
Tips for the interview: Good hands on towards problem-solving and algorithm, practice
from Geeksforgeek and https://www.interviewbit.com/, HLD and LLD, prepare well for
Amazon’s leadership principles.
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-434-for-sde-2/
1051
Chapter 442
1. https://www.geeksforgeeks.org/largest-sum-contiguous-subarray/
2. Given a list of transaction between friends who have to give or take some
amount of money from one another. Now, they have to settle up with mini-
mum number of transactions. Also, you have return a list of all the transac-
tions. For
example – If B owes A Rs. 200 : B->A = 200.
ilarly, if C owes B Rs. 200 : C->B= 200.
the minimum number of transactions is 1 and that should be : C->A = Rs. 200
1052
Chapter 442. Set 435 (For SDE-2)
2. Design question: There is a passport office with 3 desks (Desk A, Desk B, Desk C)
and 1 token machine. A person comes in and takes token from the token machine.
He has to visit every desk in sequence whenever his token number is displayed on the
particular desk. He just asked me to write the classes for the same.
1. Player vs. AI
2. Player vs. player (Offline)
3. Player vs, player (Online)
Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-435-for-sde-2/
1053
Chapter 443
• Started off with the usual “Tell me something about yourself.” The Interviewer was
very friendly.
• He asked me about several types of Tree-based Data Structures and their properties.
(T’s, BT’s, BST’s, AVLT’s, etc.)
• He asked me to write a function that takes the Root Node of a Tree as an input,
returns 1 if the tree is a BST and 0 otherwise.
– I gave him a linear approach with O(n) time-complexity and O(log(n)) or
O(height of the tree) extra stack-space complexity. He was satisfied with it.
• He gave me an array consisting of only 0’s, 1’s and 2’s and asked me to sort it.
1054
Chapter 443. Amazon Campus Drive (For Semester-Long-Internship)
– I gave him the counting sort approach with O(n) time-complexity and O(1) extra
space. He asked me if I could do it in one pass.
– I tried for some time and with the help of few hints I was able to code-out
a segregative approach. Related Articles (http://users.monash.edu/~lloyd/
tildeAlgDS/Sort/Flag/)
• He gave me a weird array of size N where N-1 elements occur K times. The remaining
one element occurs only 1 time. Find that one element which occurs only 1 time.
– I gave him a hashing based solution with time and extra-space complexity of
O(n). He then asked me how std::unordered_map and std::map are implemented
underneath. I briefed him about them. He then asked me if I could do the
problem in O(n) time and O(1) extra-space.
– He told me to think in terms of bits. Then by taking some examples I was able
to arrive at the solution. An example where K = 3 (https://www.geeksforgeeks.
org/find-the-element-that-appears-once/)
• He then asked me some questions related to Gujarat (my native place). How good is
food, tourist places, traveling and all. This discussion went on for 10 minutes. Then
he asked me about some good places to eat in Jaipur (my college was in Jaipur). I
gave a few suggestions. He was very friendly and even told me that I’m sending you
for the second F2F round.
• The usual “Tell me something about yourself.” I told him I was the best Counter-
Strike player of the Batch and he was intrigued. He asked if I knew how the game
worked. I was able to give him satisfactory information.
• He asked me to brief him about my previous round, what were my approaches to the
questions.
• He asked me about the basic idea of Dynamic Programming. He asked me about my
thoughts on “Where? and How? are Graphs useful in tackling real world problems.”
• He asked me whether I know about Segment Trees and Fenwick Trees or Binary-
Indexed Trees and about their implementations. He didn’t ask me to code them.
• He gave me an Graph in the form of Adjacency Matrix and a separate array A for
values of the nodes. He told me to transform the array A according to the following
transformation :
– The new node values should be equal to the sum of product of the sum of odd-
value nodes and the sum of even value-nodes in the sub-graph of that node
and the node-value itself. i.e. (new_node_val = old_node_val + PROD-
UCT(SUM(odd_node_value nodes in the subgraph), SUM(even_node_value
nodes in the subgraph) ) )
– A gave him a simple DFS approach. He told me that I was the first one who gave
me the solution and was satisfied.
• He told me that we want to answer Q queries (Q <= 1e4). In each query, we will be
given a number N (N <= 1e4) and we have to return 1 if N can be expressed as sum
of powers of numbers less than X (X <= N). Also anything power 1 is not allowed
1055
Chapter 443. Amazon Campus Drive (For Semester-Long-Internship)
(Otherwise there’s no point in solving as N can always be expressed as N^1). E.g for
N = 242 and X = 7 : return 1 (as 242 = 1^2 + 3^2 + 6^3 + 2^4).
– He gave me a hint to see how many numbers in total can you can use to express
N. Total Numbers = (2^2, 2^3, …… 2^(log2(N)), 3^2, 3^3, ……, 3^(log3(N)), ……,
X^2, X^3, ……, X^(logX(N))). This turned out to be very few.
– At this point I was able to reduce the problem to finding a subset with a given
sum (here N). I gave him DP solution and he was satisfied. Related Articles
(https://www.geeksforgeeks.org/subset-sum-problem-dp-25/)
• Around 7 people were selected and I was glad I could make it. It turned out to be
great experience from my side. The Interviewers were very friendly and helpful.
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Source
https://www.geeksforgeeks.org/amazon-campus-drive-for-semester-long-internship/
1056
Chapter 444
Source
https://www.geeksforgeeks.org/amazon-india-sde-iii-interview-experience/
1057
Chapter 445
1058
Chapter 445. Amazon Internship Interview Experience On-Campus
3. Reverse words in Given String.Example: Let the input string be “i like this program
very much”. The function should change the string to “much very program this like i”.
But the string is not stored in Normal Character Array. Here each character is a node
in Linked List (including space too).
4. Then he asked me about LRU Cache. and asked about How it is Implemented. i was
not able to answer quite correctly but somehow i came up with Linked List approach.
This round lasted about 45 minutes.I was asked to write code on Paper. The Inter-
viewer was quite helpful.
Round 3: Guys who did good in 1st interview were called for 2nd interview.
The interviewer asked me what questions i was asked in 1st round.
(a) Given a Binary Tree check whether it is sum tree or Not. https://www.
geeksforgeeks.org/check-if-a-given-binary-tree-is-sumtree/
(b) Then he asked to design a Data Structure for KeyBoard. Given the layout of
keyboard implement it. I initially gave him matrix based solution but he told me
to think better then i gave him graph based solution.
(c) Then He asked me about my project. Donot write any fake project only do write
your project on Resume if you have done it and you know the basics related to
project very well.
And this Interview also lasted about 40 Minutes. And Finally 15 students were Se-
lected and Luckily I was One of them �
last thing i would like to say is Be Confident.
Please Improve this article if you find anything incorrect by clicking on the ”Improve
Article” button below.
Source
https://www.geeksforgeeks.org/amazon-internship-interview-experience-on-campus/
1059
Chapter 446
Round 1 (online): The online round consisted of 2 coding problems and around 20 MCQ’s
Problem 1 : https://www.geeksforgeeks.org/count-number-ways-reach-given-score-game/
In the above mentioned link they have considered that order does matter but in the online
round they had specified that order does not matter .
Problem 2 : https://www.geeksforgeeks.org/length-smallest-sub-string-consisting-maximum-distinct-characters/
31 students were shortlisted for further rounds.
Advice : The problems that are asked in online round are not that tough, anyone
with little bit of practice can clear it with ease . So keep practicing �
Round 2 ( F2F-1….100 mins ) :The interviewer was cool and he made sure that I was
comfortable and then he started.
He just had a look on my Resume and then started giving me problems
Problem 1: Given M and N.Calculate the number of ways to form M digit number such
that value at any digit can be at most N and value at current digit is at least twice the value
at previous digit(The condition should be satisfied at every digit index, for example if M=3
and N=9 then 136 is a valid number and 135 is invalid)
He said that N can be anything and the final number can contain more than M digits if
you are thinking in decimal number system.Basically he wanted to say that don’t restrict
1060
Chapter 446. Amazon Interview Experience 6 Months Intern for SDE-1
yourself to decimal number system consider a ideal number system with maximum digit
value N.
Hint-Dynamic Programming.
Problem 3 : Given N points in 1-D plane (x -axis) with their co-ordinates and M
boxes.Place M boxes (every box should be placed on one of the N points ) in such a way
that the minimum distance out of distances of every pair of adjacent boxes get maximized
( i.e make minimum distance as large as possible )
Hint-Binary search on answer
I was able to solve all the above 3 problems but i found them very difficult . It took quite
a bit of time and scratching of head to solve them. Interviewer was always supporting and
he was motivating me to solve problem and he kept on giving me hints through out the
interview.
Advice- Be confident and take your time and keep on telling interviewer about what you
are thinking and what your thought process is .He is more keen to see your thought process
rather than your final solution.
Round 3(F2F-2 ….. 50-60 mins): The interviewer was very chill .He just told me to
assume as if I am giving an interview to one of my close friend.Then he started the interview
Problem 1 : https://www.geeksforgeeks.org/shuffle-a-given-array/
Problem 2 : https://www.geeksforgeeks.org/find-next-greater-number-set-digits/
Problem 3 : https://www.geeksforgeeks.org/wildcard-pattern-matching/
Then he shifted his focus towards computer science fundamentals . He asked me to explain
normalization in DBMS and all the normal forms also.
After this he asked me to explain how and why hashing is done ( a small discussion on it )
then he asked me about Map and some STL function on about how they are implemented
in c++ i.e internal working and a little code explanation of them
1061
Chapter 446. Amazon Interview Experience 6 Months Intern for SDE-1
In this round the interviewer was more sort of interested in my approach not the solution
and he didn’t expected me to solve all the problems just was motivating me to approach
nicely.
Round 3 over . Now comes the best part . I was given SLI ( 6 months intern )at Amazon
India and my happiness was sky high.
Final Advice – Practice makes a man perfect.Keep on practicing and your hard work will
always be rewarded.You just have to be patient and confident.
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-6-months-intern-for-sde-1/
1062
Chapter 447
Source
https://www.geeksforgeeks.org/amazon-interview-experience-on-campus-for-2-month-internship/
1063
Chapter 448
1064
Chapter 448. Amazon Interview Experience SDE2
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Source
https://www.geeksforgeeks.org/amazon-interview-experience-sde2/
1065
Chapter 449
#include <stdio.h>
int main()
{
int a[] = { 7, 7, 8, 8, 9, 1, 1, 4, 2, 2 }, i = 1, m = 10;
// int a[]={7, 8, 8, 9, 1, 1, 4, 2, 2, 7}, i=1, m=10;
if (a[0] == a[m - 1]) {
i = 2;
m = m - 1;
}
for (; i < m; i++)
if (a[i] == a[i - 1])
i++;
else
printf("%d\n", a[i - 1]);
return 0;
}
Input:
7, 7, 8, 8, 9, 1, 1, 4, 2, 2
Output:
1066
Chapter 449. Amazon Interview Experience
9
4
Round II:
In second round a question asked was asked regarding BST. Sum of key elements in indi-
vidual path of BST (just say this sum as path_ weight) and threshold path weight is given
as input. If any of the pathweight is less than oversold path weight then that should be
deleted from the tree.
Example :
Input:
Consider the below tree as input and threshold path weight is 110.
Output:
Below are the no of paths the input tree can make
path 1 : 50 -> 30 -> 20, Sum = 100
path 1 : 50 -> 30 -> 40, Sum = 120
path 1 : 50 -> 70 -> 60, Sum = 180
path 1 : 50 -> 70 -> 80, Sum = 200
In the current scenario path is less than the threshold path weight (100 < 110), So we have
to destroy the path 1.
1067
Chapter 449. Amazon Interview Experience
#include <stdio.h>
#include <stdlib.h>
struct node {
int key;
struct node *left, *right;
};
struct node* newnode(int element)
{
struct node* temp = (struct node*)malloc(sizeof(struct node));
temp->key = element;
1068
Chapter 449. Amazon Interview Experience
1069
Chapter 449. Amazon Interview Experience
1070
Chapter 449. Amazon Interview Experience
1071
Chapter 449. Amazon Interview Experience
In addition to the existing code for BST in geeksforgeeks and below function will implement
the above task.
https://www.geeksforgeeks.org/binary-search-tree-set-2-delete/
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Source
https://www.geeksforgeeks.org/amazon-interview-experience/
1072
Chapter 450
Amazon On-Campus – 6
months Internship (SDE)
There were 2 coding questions and 20 mcqs of variable marks such as 4, 6 and 2 and no
negative marking.
Question 1- Stock span problem
https://www.geeksforgeeks.org/the-stock-span-problem/
Question 2- Zig-Zag traversal. The only catch was the tree was given in the form of array
like 3, 2, 4, 5, null, null, 1, 1, 2, 12. All internal nodes would have either a value or null.
Leaves could be empty. It was more of implementation tester.
24 students were shortlisted. (Mostly based on MCQs because the coding was done by many
).
Round 2: Tech Round (Purely based on GeeksForGeeks DSA)
I was asked about the test and how I solved the questions. Then I was asked
https://www.geeksforgeeks.org/maximum-profit-by-buying-and-selling-a-share-at-most-
twice/ . First I was asked my algorithm and then I was asked to code it all on paper.
Then he asked about my hobbies.
13 Students made it to Round 3.
Round 3: Tech Round ( GeeksForGeeks and Problem solving skills tester )
Given a graph create a tree with minimum depth. I was not asked to write the code but
the discussion went on for about 5 to 10 mins.
1073
Chapter 450. Amazon On-Campus – 6 months Internship (SDE)
Finally after a whole day of Process 9 Students were selected for Internship and
I was One of Them.
PS- GeeksForGeeks is the go to site for Amazon Interviews !!!!
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Source
https://www.geeksforgeeks.org/amazon-on-campus-6-months-internship-sde/
1074
Chapter 451
1075
Chapter 451. Amazon QA role & Support Engineer Intern interview experience
Output:11001
2) Given a binary tree. Check whether it is a binary search tree or not?
3) perform binary search
4)find the peak elements(the value should be greater than the previous element and the next
element in the array) in the array.
Input:- 5 4 8 6 9 1 10
Output:-5 8 9 10
After qualifying in this round u will be shortlisted for round 3.
Round 3:
In round 3, depending upon the panel they will ask you about your project.
Basic and advanced linux commands that are used for testing.
If you had done a project they will ask you like ” how do you test your project”.
Basic concepts in OS and DBMS.
What is cache memory.
What is IPV4 and IPV6.
How will gmail authenticate your passwords?
In which memory your laptop password is being saved?
Deadlocks.
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Source
https://www.geeksforgeeks.org/amazon-qa-role-support-engineer-intern-interview-experience/
1076
Chapter 452
Recruitment Process:
Amazon conducts 5-6 rounds to select freshers as SDE (SDE-1) in their organization. The
following rounds are conducted:
• Written Round
• Online Coding Round
1077
Chapter 452. Amazon Recruitment Process
Written Round:
The Written round majorly consists of two sections namely Aptitude / Logical Test and
technical test. The technical test contains questions mainly from C, C++, Operating System,
Data Structure, inheritance, functions. Generally in MCQ format with a given time frame
of about 30 minutes.
Online Coding Round:
This round is hosted online and the candidates are presented with 3-4 coding questions, the
questions are of intermediate difficulty, mainly from Arrays, strings, and matrices.
To clear this round, one should have a strong understanding of these data structures.
Telephonic Round:
This round is purely algorithmic based with around 2-4 questions ranging from arrays, trees,
to dynamic programming problems. You are to present algorithm and in some questions,
the code also if necessary. Apt candidates are selected for further rounds.
Technical Round 1:
Technical rounds are face-to-face algorithmic rounds in which candidates are presented with
2-4 questions, all from data structures. The most commonly asked DSs are the matrix,
binary tree, BST, Linked list.
Technical Round 2:
Same as previous round, however the difficulty is increased and more questions from Trees,
BST, and Tries are asked. One should have a clear knowledge of tree-based recursion, and
the standard questions based on it are a must.
Hiring Manager Round:
This is generally the most technical-intensive round, with questions ranging from the projects
you have done, the technology used in them, design problems and DS/Algo problems and
tricky puzzle-like questions.
HR Round:
You can expect HR questions like :
1. Tell me about Yourself, your family
2. How do you see yourself five years from now?
3. What are your strengths and weaknesses?
4. Some technical questions can also be asked from topics like OOPs.
Questions asked in Amazon:
1. Kadane’s Algorithm
2. Angle b/w hour and minute hand
3. Inversion of array
4. Paranthesis Checker
5. 0-1 Knapsack
6. k Largest elements
7. Longest Palindromic
1078
Chapter 452. Amazon Recruitment Process
8. Array to BST
Interview Experiences:
Amazon interview experience | SDE 1
Amazon interview experience | SDE 1
Amazon interview experience | SDE 1
Read all Amazon Interview experiences
Where to apply?
Amazon Careers
Source
https://www.geeksforgeeks.org/amazon-recruitment-process/
1079
Chapter 453
1. There are n balls of different weights, we need to melt all the balls to make a new big
ball. The cost to melt two balls is equal to sum of their weights. We need to melt the
balls with minimum cost.
For example if we are given 4 balls of weights 4, 3, 2 and 6. We can melt the balls in
following ways.
1) First melt balls of weight 2 and 3. Now we have three balls of weight 4, 6 and 5.
2) Now melt balls of weight 4 and 5. Now we have two balls of weight 6 and 9.
3) Finally melt the two balls and all balls have melted to a big ball.
Total cost for melting all balls is 5 + 9 + 15 = 29
This is a variation of connecting ropes question on geeks: https://www.geeksforgeeks.org/connect-
n-ropes-minimum-cost/
2. Find k largest/smallest elements in an infinite stream of integers. Elements in the
stream can be in any order.
https://www.geeksforgeeks.org/kth-largest-element-in-a-stream/
https://www.geeksforgeeks.org/k-largestor-smallest-elements-in-an-array/
1. https://www.geeksforgeeks.org/a-linked-list-with-next-and-arbit-pointer/
Working code was expected on the paper. We discussed many approaches to solve the
questions. He picked one out of those and asked me to write a production ready code.
He was very happy with the code and left without asking another question �
1080
Chapter 453. Amazon SDE-2 Interview Experience
Tips :- Take your time and thought through the code you are about to write. THINK
ALOUD!! Write a rough pseudo code before the actual code so that you get an idea of all
the variables you will be needing and maintain modularity of the code. Do dry run the code
with the edge cases.
Round-3 (F2F Round-2)
1) LLD of a system in which players can play in a tournament of matches. A match is
played between 2 players. Assume you have sufficient 2^k registered players ready for a
tournament. Match Flow:
Player 1 and 2 rolls a dice one by one and a single chance is given to each player. There is
an umpire who also rolls dice after the two players and he calculates the absolute difference
between the number on the dice with the two players. The player having minimum diff with
the umpire score wins the game. If there is a tie, then umpire chooses to throw a coin and
the two players get to choose a face, and decides the winner.
2-3 behavioural questions.
I screwed up this interview. I created an average design. He didn’t seem happy about it.
Tips: Don’t get disheartened. You will get two more design rounds to ace the process.
Round-4 (F2F Round-3)
1) There were two interviews in this round. They asked me to design a movies reviews
aggregator system. Data should be fetched from movie rating providers like imdb, rotten
tomatoes, etc
We had a lot of discussions regarding the issues you might face if the reliability of the movie
rating providers goes down/up or you remove a provider or you add a new provider. eg
you consider imdb to be more reliable(some factor) than rotten tomatoes in your rating
calculations. How you will keep the data. How you will perform search. Is it a NRT data
or you will do the data processing offline. How do you rank your listing of movies. Lot of
factors were discussed and we end up with a good design. Both of the interviews seemed
happy.
Tips: Don’t lose your calm if any of the round goes average or even below average. They
will tell you very genuine drawbacks in your design and you need to evolve your design. This
is what they are looking for.
Round-5 (F2F Round-4) Hiring Manager
1) All together there were 10-15 behavioural questions to check the candidate’s alignment
towards the amazon leadership principles. It’s a must to enter into Amazon.
Use STAR( Situation, Task, Actions, and Results) approach to answer each of these ques-
tions.
eg. xxx was the situation. yyy are the tasks you identified. you executed the tasks. zzz was
the result.
2) There is a device like kindle where you can buy books and read them. You can read the
same content using kindle app on other devices as well like on your phone, tab etc. There
was a problem in that and he need a design to solve this. The problem is suppose I was
reading an xyz book and I was on a specific page let’s say at 60. Now I closed the app on
the device and I opened the same book on other device. The same page should open where
I left on the other device. How will you handle the actions user take when he is offline. Lot
of discussion around this.
He was very happy about the design. I solved it using operational transformation being
1081
Chapter 453. Amazon SDE-2 Interview Experience
used by the websites for online collaboration like google doc, collabedit etc.
Source
https://www.geeksforgeeks.org/amazon-sde-2-interview-experience/
1082
Chapter 454
Source
https://www.geeksforgeeks.org/amazon-sde-intern-experience/
1083
Chapter 455
1084
Chapter 455. Amazon Web Services(AWS) Interview Experience (On-Campus)
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Source
https://www.geeksforgeeks.org/amazon-web-servicesaws-interview-experience-on-campus/
1085
Chapter 456
Source
https://www.geeksforgeeks.org/amazon-telephonic-interview-questions-sde-1/
1086
Chapter 457
• Maximum sum subarray such that no elements are consecutive – Practice here
• Edit distance
• Assembly line scheduling
1087
Chapter 457. Amazon’s most asked interview questions
Source
https://www.geeksforgeeks.org/amazons-asked-interview-questions/
1088
Chapter 458
Level – Medium
1089
Chapter 458. Amazon’s most frequently asked interview questions | Set 2
2. Minimum cost required to travel from top left to the bottom right in a matrix
3. Maximum difference between node and its ancestors – Practice here
4. Min distance between two given nodes of a binary tree – Practice here
5. Find the number of island – Practice here
6. Topological Sort – Practice here
7. Detect cycle in a directed graph – Practice here
8. Flattening a link list – Practice here
9. Detect a loop in a linked list – Practice here
10. Check if a binary tree is BST or not
11. Min Cost path
12. Count ways to reach nth stair
13. Maximum Subarray Problem
14. Palindrome Partitioning
15. Given a binary tree find the minimum root to leaf height.
16. Implement LRU cache
Level – Hard
Also see
Source
https://www.geeksforgeeks.org/amazons-most-frequently-asked-interview-questions-set-2/
1090