Amazon Interview Experience | Set 174 (For SDE)

Recently I went through Interviews for SDE position in Amazon Development Centre, Chennai. Here is my Interview experience:

Telephonic round:
1) Given an array with lengths, you have to select 3 lengths (a, b and c) for a triangle such that it satisfies condition a+b>c,b+c>a, a+c>b. Find the number of possible triangles can be created from the given array.
ex: 3 5 6 9 10
(3,9,10), (3 5 6), (5 6 10), (5 9 10), (5 6 9), (6 9 10)
so number of possible triangles is 6

2) Count Inversions in an array
Inversion Count for an array indicates – how far (or close) the array is from being sorted. If array is already sorted then inversion count is 0. If array is sorted in reverse order that inversion count is the maximum.
Formally speaking, two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j Example: The sequence 2, 4, 1, 3, 5 has three inversions (2, 1), (4, 1), (4, 3).
In house Interview 1(F2F):

3)Next Greater Element
Given an array, print the Next Greater Element (NGE) for every element. The Next greater Element for an element x is the first greater element on the right side of x in array. Elements for which no greater element exist, consider next greater element as -1.
Examples:
a) For any array, rightmost element always has next greater element as -1.
b) For an array which is sorted in decreasing order, all elements have next greater element as -1.
c) For the input array [4, 5, 2, 25}, the next greater elements for each element are as follows.

Element       NGE
   4      -->   5
   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

4)Sorted Array to Balanced BST
Given a sorted array. Write a function that creates a Balanced Binary Search Tree using array elements.
Examples:

Input:  Array {1, 2, 3}
Output: A Balanced BST
     2
   /  \
  1    3

Input: Array {1, 2, 3, 4}
Output: A Balanced BST
      3
    /  \
   2    4
 /
1

Inhouse Interview 2(F2F):
5) Detect Cycle in a Directed Graph
Given a directed graph, check whether the graph contains a cycle or not. Your function should return true if the given graph contains at least one cycle, else return false. For example, the following graph contains three cycles 0->2->0, 0->1->2->0 and 3->3, so your function must return true.

6) Convert a BST to a sorted circular doubly-linked list in-place.

Telephonic Round with Hiring Manager:
Introduction about me.
Then he asked about my college project. we discussed the OO design for the project.
Then he asked me about my current company’s latest Invention
Then he asked me about Virtual memory and some in depth discusion on that.
Then he came to my current project I am working
Then he asked me why are you coming out of my current company??
Then he gave a question to solve.
7)Given an array A[] and a number x, check for pair in A[] with sum as x
Given an array A[] of n numbers and another number x, determines whether or not there exist two elements in S whose sum is exactly x.
He asked about various possible solutions for the above one.

Bar raiser round(F2F):
8)Given a binary tree, find the diameter of the tree.
The diameter of a tree (sometimes called the width) is the number of nodes on the longest path between two leaves in the tree.

After solving the above one, he added a constraint on the above problem: (i.e) To find the diameter of the tree with atmost one turn
Examples of turns in tree:
In tree1-> start from 1 and there is a turn at root 2 towards right,
In tree2-> starts from 3 goes in left and there is a turn at 1 towards right ,
In tree3-> starts from 1 goes in right and there is a turn at 3 towards left,

     2                 3                 1
    / \               /                   \
   1   3             1                     3
                      \                    /
                       2                  2

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.


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



My Personal Notes arrow_drop_up


Article Tags :
Practice Tags :


Be the First to upvote.


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