Amazon Interview Experience | Set 322 (Off-Campus)

3.6

Recently I attended interview at Amazon for SDE 1 profile.

Round 1 (Written):
3 questions were given and I was asked to write the executable code in any language.

  1. Check whether the tree is BST. (O(n) time).
  2. Check whether the Linked List is Palindrome. (O(1) space).
  3. One array (Array 1) of size m with m sorted elements and another array (Array 2) of size (m + n) with n sorted elements, you have to put all the elements from both the arrays in Array 2 in sorted order. (O(1) auxiliary space and O(m + n) time).

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.


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.

Round 4 (Design Round):

  1. Design a Parking Lot.
  2. Create queue using stack.
  3. Discussion on all the OS scheduling Algorithms.
  4. How to implement SRTFS (preemptive SJF).
  5. Discussion on Inter Process Communication : Shared Memory and Sockets.
  6. Why sockets are preferred over Shared Memory.
  7. Where shared memory is stored (in user space or kernel space) ? and why ?

Round 5(Hiring Manager Round):

  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

    Consecutive sequence of maximum length: [66, 67, 68] of length 3.

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:

  1. Practice coding on paper, try to do write clean code without overwriting.
  2. Brush up important concepts of OS.
  3. They concentrated more upon the thought process to reach the final solution. So think loudly and you will receive hints ;).
  4. Keep calm and remain confident.

Thank you Geeksforgeeks !!!

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.

GATE CS Corner    Company Wise Coding Practice

Recommended Posts:



3.6 Average Difficulty : 3.6/5.0
Based on 11 vote(s)