Sei sulla pagina 1di 5

Amazon Programming and Technical Interview Questions

1. Two numbers are represented by 2 linked lists. Find the resultant linked
list represented as sum of these given linked lists.
2. Given a number say 12345, find the immediate next number using the
same digits, in this case 12354.
3. 3 points of a triangle are given. Find if given forth point lies inside or
outside of the triangle.
4. Given a Hotel and checkin/Checkout time of visitors, find the maximum
numbers of rooms required. (different version of Trains/Platform
question)
5. Given sequentially placed boxes, each representing a number( which
may be positive or negative), we need to select the numbers in order
to have the maximum sum, having the constraint that if we select a
given box, we cannot select adjacent box to it, but can select any
other.
Solution : let the boxes positions be the indexes of array and their
values as array values. then if we select value at index 0, we cannot
select value at index 1, but can select from index 2,3,, and so on.so we
can apply Dynamic programming here.
6. Given a linked list eg : 1->2->3->4->5->6, make the following changes
1->6->2->5->3->4
7. Given a pre-order traversal, construct a binary search tree.
8. Given an alien dictionary, find the order of the alphabets in the
dictionary.
9. Connect n ropes with minimum cost
10.
Find the maximum element in an array which is first increasing
and then decreasing
11.
Find the Pythagoras triplet in an array
12.
Given a very large binary number which cannot be stored in a
variable, determine the remainder of the decimal equivalent of the
binary number when divided by 3
13.
Find a peak element
14.
Top View of binary tree
15.
Maximum difference between node and its ancestor in Binary
Tree
16.
Given an array of distinct integers, find if there are two pairs (a,
b) and (c, d) such that a+b = c+d, and a, b, c and d are distinct

elements. If there are multiple answers, then print any of them.


Expected complexity : O(n2)
Ex : 3,4,7,1,2,9,8
Output : (3,8) and (4,7)
17.
Lowest Common Ancestor in a Binary Tree
18.
If I am designing a media player and I want to store songs and
play them in random order
a) What data structure will you use to store songs?
b) How will you select the next song to play in a way which prevents
the same song being played in consecutive turn.
19.
Clone a binary tree with random pointers
20.
Maximum triangle path Sum : Starting from the top of a pyramid
of numbers like below, you can walk down going one step on the right
or on the left, until you reach the bottom row:

One of such walks is 55 -> 94 >- 30 -> 26. You can compute the total
of the numbers you have seen in such walk, in this case its 205.
21.
Design your own Process Control Block(PCB).
22.
Reverse a linked list.
23.
Given a 1D array where each cell represents a toll gate ticket
value. Find the minimum number of tickets needed to surpass the
whole array (means till u reach the end of array) .
If ticket value is 1 then u can pass that cell alone. If ticket value is 2 u
can pass that cell and the next cell.. that is how ticket values work.
Eg : Input : 3 1 5 4 1 1 1 Output :In this case if v buy ticket from a[0]
and a[2] meaning two tickets are enof to pass this array.

24.
Convert a BST to sorted doubly linked list without any extra
space. (only ptrs to nodes should be created ,no new node creation is
allowed.)
25.
In a sorted array every number is present twice, only one
number is present one time. You have to find the number occurring
once. Expected complexity : O(log N)
Ex : 101, 101, 200, 200, 301, 450, 450
Output : 301
26.
Clone a binary tree with random pointers
27.
Next greater element
28.
You have been given a grid with some doors, walls and some
empty spaces.
1st part : You have to tell the least no of moves to go from random
position in the grid to the nearest door. You can move in four directions
only, i.e, left, right, above, below.

2nd part : Least distance of every empty cell to the nearest door
29.
Given an unsorted array, trim the array such that twice of
minimum is greater than maximum in the trimmed array. Elements
should be removed either end of the array.
30.
Given a value V, if we want to make change for V cents, and we
have infinite supply of each of C = { C1, C2, .. , Cm} valued coins,
what is the minimum number of coins to make the change?
31.
In a BST, replace value of each node with the sum of itself and
everything greater than itself.
32.
here are two very large numbers, cant fit in any data type
provided, so they are given in a linked list (one digit per node). Sum
the two numbers.
33.
In an integer array, find the window with maximum sum.

34.
Check if a given binary tree is BST or not.
35.
In a BST, each node has an additional attribute score along with
the value. You need to write two functions:
a. Update(value, newScore) -> update the score of the node with value
value to the newScore
b. SubTreeScore(value) -> get the sum of scores of all nodes in the
subtree with node having the value value as the root
Interviewer wanted O(logn) solution for Update and O(1) for
SubtreeScore function. We are allowed to change the structure of the
node to add additional attributes
c. Discussion on the above solution for the case where nodes are
deleted from the tree(How to still have O(1) solution for SubTreeScore)
36.
Given a matrix, with each node having a value. You start from 0,0
and have to reach n,m. From i,j you can either go to i+1,j or i,j+1.
When you step on each block, the value on that block gets added to
your current score. Whats the minimum initial score you must carry so
that you can always reach n,m(through any possible path) having
positive score at the end.
Eg: Matrix ->
2 3 4
-5 -6 7
8 3 1
Ans -> 6 for path 2,-5,-6,3,1 we need initial score of 6 so that when
we land on 1, we have a positive score of 1
37.
Linked list containing characters as values. Find if a linked list is
palindrome.
38.

pow(a,b) needed to cover each and every case possible

39.

LRU cache implementation

40.
Given an array of numbers, form the largest number possible by
concatenating all of them. Needed to return a string.

Note: i) For more questions visit:


http://www.geeksforgeeks.org/tag/amazon/

ii) 262 sets of Amazon Interview experience


(Programming round, Technical,
Face to Face) are available at the above link
iii) You can also find solutions (coding) for all the
programs given above

Potrebbero piacerti anche