Amazon Interview Experience for SDE-I

 

Online coding test:

Three coding question were there on the hackerearth platform. It’s 70 minutes test.

1) Find next greater number with same set of digits. If next greater element does not exist print “-1”.

Input: n=327698

output: 327869

https://www.geeksforgeeks.org/find-next-greater-number-set-digits/

2) Given array of  elements with zero and one only, you can do following operation at-most one time.

operation: flip all elements from i to j index where i<=j.

Now you need to print maximum number of one in array after doing these operation.

Input:

n=6

1 0 0 1 0 0

Output: 5

3) Given array and integer k you need to tell that whether array can be sorted or not after following operation any number of times.

operation: you can swap (i) index element with (i+k) index element any number of times.

Print the sorted array if the array can be sorted by doing the above operation or print “-1”.

Input1:

n=8 k=2

1 2 7 8 3 4 5 6

Output1:

1 2 3 4 5 6 7 8

Input2:

n=8 k=2

1 4 5 6 7 8 2 3

Output2: -1

 

Round 1:

1) Tell me about your self.

2) Given binary tree, complete path is defined as root to leaf. The sum of all nodes on that path is defined as sum of that path. Given number K you need to remove the nodes in binary tree which don’t lie in any path with sum>=K.

The function was given with root of binary tree and K you need to return the root after removing the nodes which don’t lie in any path with sum>=K.

Input:

K=8

 

 

Output:

 

https://www.geeksforgeeks.org/remove-all-nodes-which-lie-on-a-path-having-sum-less-than-k/

3) Given rotated sorted array find the minimum element in the array.

Input:

n=8

7 8 1 2 3 4 5 6

Output: 1

https://www.geeksforgeeks.org/find-minimum-element-in-a-sorted-and-rotated-array/

 

Round 2 (Managerial round over video call):

1) Tell me about yourself.

2) Current role in the company.

3) Project you liked the most worked in the corporate life.

4) Time when you are given task and you are not able to complete on your own and take help of other colleague.

5) Time when you have received  critical feedback from your manager and how did you improve it?

6) Extra work you have done in the previous company apart from your regular work.

7) Which was the most critical task in your work in previous company and how did you manage that?

 

Round 3:

1) Tell me about yourself.

2) Stream of customer ID and product ID are arriving continuously. Now there will be query at any moment of time. You need to answer the query.

Query: Given product ID, number of the product with this product ID sold to customer.

Input:

Current Entry:

pID      cID

1          499

3          421

1          645

1          989

2          424

Query: pID=1

Output: 3

How will you space optimised this problem?

3) Number is arriving in the stream and the fixed K is given in the starting of Input. The below query can be asked at any moment of time. You need to answer the query.

Query: find K th maximum element in current stream.

Input:

K=3

Current Stream: 8 7 1 2 4 5 9

Output at the moment: 7

https://www.geeksforgeeks.org/kth-largest-element-in-a-stream/

4) In the binary tree leaf’s left and right node will not be null. one leaf’s right node will be connected to node which is next leaf in the in order traversal. and the leaf’s left node will be connected to previous leaf according to in order. First leaf’s left will be the last leaf in the in order traversal and last leaf’s right node is connected to first leaf in the in order traversal.

You need to print in order traversal.

Expected Time Complexity: O(n)

Expected Space Complexity: O(1)

Input:

 

Output:

4 2 6 5 7 1 8 3 9 10

5) Write the optimised code for LRU Cache.

Size of LRU cache will be given in the input.

6) What is polymorphism?

 

Round 4 (Bar Raiser round over video call):

1) Tell me about yourself.

2) Check If one BST is subtree of another BST.

Function will be given with root1 and root2 as parameter of BST-1 and BST-2 and will return true if second BST is subtree of first BST or return false.

Note: Elements can be repeated. BST was created with all less or equal element will go to left child of node and greater element will be on the right child of the node.

Input:

 

Output: true.

 

Result: Hired!!

Write your Interview Experience or mail it to contribute@geeksforgeeks.org



My Personal Notes arrow_drop_up

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

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


2


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.