# Amazon Interview | Set 102

I had my Amazon Interview some days back and now I am posting my experience here.

**Round 1 (Apt)**

20 mcq question and 2 coding questions were there

Mcq consisted of questions from C, Data Structure, OS, and so on

**Coding Question 1** â€“ Given a String and a pattern find all anagrams of the pattern in the original string. You need to print all the index of the location where the match was found

Ex â€“

INPUT – ABDACDBACA

ABCD

OUTPUT â€“ 1 3 4 5 (at index 1 BDAC , at index 3 ACDB and so on )

**Coding Question 2** â€“ Given an array containing zero and non zero digits you need to shift all the zeroes to the right of the array. Output should be number of non zero elements present in array and minimum number of swaps needed to do so.

Ex â€“

INPUT â€“ 1 0 -6 5 0 0 2 0

OUTPUT â€“ 4 (number of non zero elements)

1 (swap 2 with 0 present at index 1)

**1 ^{st} PI**

Started with a general introduction with the interviewer. Some basic introductory questions like Tell me something about yourself and after we were settled he started asking question

1 . Given a binary tree store the vertical sum of the tree in a list.

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

**2 ^{nd} PI**

General Introduction about myself and asked me my Weakness and strongness and again once we were comfortable started asking questions

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

**3 ^{rd} PI**

Started with introduction and then he gave me question

- Given an nâ€“ary tree .Print the right view of the tree.

After that he added to print the right view in a zigzag way like first element from top element , second from bottom third from top fourth from bottom and so on. Then asked to print both the left and right view of the tree - Given an array of 0â€™s and 1â€™s print the numbers in the form of Fibonacci sequence i.e. 1
^{st}1 zero then 1 one then 2 zero then 3 one and so on

Ex â€“INPUT â€“ 00101111011101011000

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)

Coding of both the programâ€™s was needed

**4 ^{th} PI (Bar Raiser)**

- 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.
- Implement the pow function in logarithmic time.
- Implement a DFA which will accept all string containing even number of 0â€™s and 1â€™s
- Find the 2
^{nd}maximum number from a table using SQL query - Check whether a grammar is ambiguous or not

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.

## Please

Loginto comment...