# Amazon Interview | Set 125 (On-Campus for Internship)

• Difficulty Level : Expert
• Last Updated : 24 Jun, 2019

Online Round
In this round there were 20 MCQs to solve and 2 coding questions. Of the 20MCQs a couple of questions were on OS, Quantitative Aptitude, Data structures etc. Most of them are there on www.geeksquiz.com. In MCQs there was – 0.25 marking for every wrong answer and +1 for right answer. Coding questions were of 10 marks each.

constraint : Space complexity should be O(1).

input : {1, 9, 8, 0, 0, -2, 0, 1, 6}.
output :
nonzero : 6
swaps : 2 (-2 as it is and swap 1 and 6 from first two zeros. )

18 were selected out of 55 for f2f round.

```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

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.

Q3 – Reverse level order traversal.
time complexity : O(n)

```Input:
1
/     \
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
7 6 5 4
3 2
1

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

My Personal Notes arrow_drop_up