Amazon Interview Questions
- 5of 5 votes
AnswersGiven three arrays A,B,C containing unsorted numbers. Find three numbers a, b, c from each of array A, B, C such that |a-b|, |b-c| and |c-a| are minimum
- Greg September 04, 2014 in United States
Please provide as efficient code as you can.
Can you better than this ???| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Arrays C++ Coding - 5of 5 votes
AnswersSay you have a keypad that has keys for the numbers 0 through 9 and the correct code is some sequence of 5 digits. This keypad does *not* reset after entering an incorrect sequence of 5 digits. ie. If the correct sequence is 12345, entering 7512345 will succeed in opening it because it ends in the correct sequence. If the keypad actually resets after every 5 digits pressed, then it would not succeed b/c it would interpret the above sequence as "75123" then "45".
- Jason May 30, 2015 in United States
1. Write an algorithm that will try to find the correct code for this keypad. Assume you have an API similar to KeyPad.pressKey(int n) where you pass in a number (0...9) and it returns true if the keypad unlocks and false if it's still locked.
Note that you could easily enter all digits of all numbers 00000 through 99999 resulting in 5*100000 key presses, but remember that the panel does not reset after every sequence of 5 digits, so find a way to do this more efficiently. Notice for example that entering the stream 3791283780 will test the length 5 sequences 37912, 79128, 91283, 12837, 28378, 83780; not only the two disjoint sequences 37912 and 83780.
Think of this keypad as remembering the last 4 keys pressed (and the order pressed); when the next key is pressed, if the last 4 keys + the current key equal the correct code, the keypad will unlock. Assume the keypad does all this internally, so you can just keep feeding it keypresses and it will eventually unlock if the last 5 keypresses entered is the correct code.
2. Generalize your algorithm to work for a keypad where you don't know the length of the correct sequence in advance.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 5of 5 votes
AnswersHad my first and second phone interview with Amazon. I was dropped. This site has been a great help towards my preparation and most questions are based on what you find here.
- S July 01, 2008
Posting my Questions is a small way of saying Thanks!
Interview 1:
1. What is polymorphism.
2. Design an OO parking lot. What classes and functions will it have. It should say, full, empty and also be able to find spot for Valet parking. The lot has 3 different types of parking: regular, handicapped and compact.
3. Coding: I have an integer array where every number appears even number of times and only one appears odd times. Find the number.
(I said hashtable and he asked me to write code with Hashtable)
4. What data structure would you use to look up phone numbers for customer names.
(I said Hashtable. Asked why hashtable, why not a tree. I said HT has O(1). Asked is order always 1, when more than O(1) in HT.
Second Interview:
1. Starter: Describe your college projects.
2. OO Design: Design a deck of cards. What classes, data structures will you use? How will you shuffle the cards? How will you divide (deck) among players. What class/function do you need to denote players and where will you add them? What class/function do you need to deck? What if I need to add 2 jokers to the deck of 52 cards.
3. Data Structures: How will you use a hashtable to find data in a tree. (Then he rephrased) suppose I have a hashtable, I want to store the data in a tree instead of a bucket. How will I do it. What complexity to find an element.
4. Bits & Bytes: Find if a binary representation of a number is palindrome. The function should work irrespective of number of bytes for an integer. Suppose if our machine is 4 bytes for an int, how will you use the program for 8 byte machine.
5. Unix: Suppose I have 100's of html files in many directories. I want to find the files having phone numbers.
b) Suppose I have 2 files having phone numbers, find the repeating phone numbers. (I said sort and grep). Then he asked what if the lines cannot be sorted.
All the best guys. I think the second interview was challenging since the interviewer was prodding until he heard a leave me alone. So it means that though they are based on questions in cc, be prepared for extensions. I think this site is all you need to prepare for Amazon interview.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Java Data Structures Object Oriented Design Coding - 5of 5 votes
AnswersGiven a binary tree.
Print nodes of extreme corners of each level but in alternate order.10 5 11 9 20 - 15 14 - - - 25 30
then output should be 10,11,9,25,30
- SK June 09, 2013 in India
left most of 0th level
right most of 1st level
left most of 2nd level
& like this| Report Duplicate | Flag | PURGE
Amazon Senior Software Development Engineer Algorithm Trees and Graphs - 5of 5 votes
AnswersGiven stock price of Amazon for some consecutive days. Need to find the maximum span of each day’s stock price. Span is the amount of days before the given day where the stock price is less than that of given day
- Rahul Sharma April 04, 2014 in India
E.g i/p = {2,4,6,9,5,1}
o/p= { -1,1,2,3,2,-1}| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 5of 5 votes
AnswersWe have a day to work and we have different kinds works do to which has start-time and end-time. We have to choose the different works so that we can achieve the maximum number of minutes in a day to work. Chosen works should not overlaps to each other.
- Rahul August 22, 2013 in India
Ex-1:
Start-Time End-Time
W1: 6:00 9:30
W2: 9:00 12:30
W3: 12:00 14:30
W4: 10:00 10:30
W5: 11:00 13:30
Solution: W1 + W4 + W3(or W5)
Ex-2:
Start-Time End-Time
W1: 6:00 8:30
W2: 9:00 11:00
W3: 12:30 14:00
W4: 8:00 9:00
W5: 10:30 14:00
W6: 9:00 11:30
Solution : W1 + W6 + W3 = 390min| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 5of 5 votes
Answerswrite a program to give an array such that:
- doctorking5891 April 29, 2014 in United States
1. the data value is from 1 to n
2. the length of it is 2*n
3. the two elements with same value keep the same number distance.
for example, when n = 3, the length of array is 6, the array should be like: 2, 3, 1, 2, 1, 3. there are two elements between "2" pair, and three elements between "3" pair and one element between "1" pair| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 5of 5 votes
Answers100 doors are closed , In first pass i open all of them , in 2nd pass i toggle every 2nd door , in 3rd pass i toggle every 3rd door , i continue it till 100th pass .. find all the doors that will remain open after 100 passes.
- anag June 26, 2013 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Brain Teasers - 5of 5 votes
Answersfind the sum of all 4 digit numbers formed from 1 , 2, 3, 4 whithout rep .
- anag June 26, 2013 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Brain Teasers - 5of 0 votes
AnswersGive an efficient algorithm to solve this problem. Given "N" files as input, find the common text fragments that occurs in all the files in input and remove them from the files.
- Anonymous September 16, 2008
(A fragment is a piece of text that has at least 3 words)
E.g.
Input
=====
File1
------
It is snowing and I want to drive home.
File2.txt
----------
It is snowing and I want to go skiing.
File3.txt
----------
It is hot and I want to go swimming.
Output
=======
Out.File1.txt
---------------
It is snowing drive home.
Out.File2.txt
-----------------
It is snowing go skiing.
Out.File3.txt
----------------
It is hot go swimming.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 4of 6 votes
AnswersGive you two sequences of length N, how to find the max window of matching
- Code2Win June 08, 2013 in India
patterns. The patterns can be mutated.
For example, seq1 = “ABCDEFG”, seq2 = “DBCAPFG”, then the max window is 4. (
ABCD from seq1 and DBCA from seq2).| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer String Manipulation - 4of 6 votes
AnswersFind the nearest leaf node from given node in binary tree.
- Vin September 08, 2013 in India| Report Duplicate | Flag | PURGE
Amazon SDE-2 - 4of 6 votes
AnswersYou are given a sequence of black and white horses, and a set of k stables numbered 1 to k. You have to accommodate the horses into the stables in such a way that the following conditions are satisfied:
- nishu May 21, 2014 in India
a. You fill the horses into the stables preserving the order of horses. For instance, you cannot put for horse 1 into stable 2 and horse 2 into stable 1. You have to preserve the ordering of horses.
b. No stable should be empty and No horse should be left unaccommodated.
c. Take the product (number of white horses * number of black horses) for each stable and take the sum of all these products. This value should be the minimum among all possible accommodation arrangements.| Report Duplicate | Flag | PURGE
Amazon SDE1 - 4of 4 votes
AnswersIf [a1,a2,a3...,an,b1,b2...bn] is given input change this to [a1,b1,a2,b2.....an,bn] , solution should be in-place
- Anonymous February 05, 2011| Report Duplicate | Flag | PURGE
Amazon Microsoft Developer Program Engineer Software Engineer / Developer Algorithm Arrays - 4of 4 votes
AnswersYou are given a large set of integers, which are not sorted. Figure out a method to retrieve the largest 1000 elements, in O(n) run time
- varunumesh77 March 12, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon Intern Algorithm Data Structures - 4of 4 votes
AnswersGiven a array of size n. Divide the array in to two arrays of size n/2,n/2. such that average of two arrays is equal.
- gowthamganguri August 29, 2013 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Arrays - 4of 4 votes
AnswersSparse number is an integer if there are no adjacent 1 in it's binary representation.
- Rahul Sharma March 30, 2015 in United States
Like: 5 -> 101 (no adjacent 1)
9 -> 1001 (no adjacent 1)
while 6-> 110 is not sparse number.
Now you are given an integer find the NEXT BIGGER sparse number.Please mind 'it is next bigger'.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Coding - 4of 4 votes
AnswersTwo finite, strictly increasing, integer sequences are given. Any common integer between the two sequences constitute an intersection point. Take for example the following two sequences where intersection points are
- blackfever June 29, 2014 in India
printed in bold:
First= 3 5 7 9 20 25 30 40 55 56 57 60 62
Second= 1 4 7 11 14 25 44 47 55 57 100
You can ‘walk” over these two sequences in the following way:
1. You may start at the beginning of any of the two sequences. Now start moving forward.
2. At each intersection point, you have the choice of either continuing with the same sequence you’re currently on, or switching to the other sequence.
The objective is finding a path that produces the maximum sum of data you walked over. In the above example, the largest possible sum is 450 which is the result of adding 3, 5, 7, 9, 20, 25, 44, 47, 55, 56, 57, 60, and 62
this is the same problem which I saw in SPOJ Problem Set| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 4of 4 votes
AnswersGiven a random generator rand(5) which generates numbers between 0 to 4. How do u generate numbers between 0 to 6, I.e. Implement rand(7).
- hulk April 16, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm Brain Teasers - 4of 4 votes
Answersgive an algorithm for finding duplicate parenthesis in a expression.
example :
- rahul May 02, 2014 in United States(( a + b ) + (( c + d )))
| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Stacks - 4of 4 votes
Answersin a tree any root can have any number of children. Every node has an integer value. Find the maximum length on consecutive number sequence anywhere in the tree. For example if root is 2 and one child is 3, its child is 4 its child is 6 then max length will be 3. I was able to write the code the find of one sequence but when one sequence ends and other starts I was not able to handle that case. I think its hard to do by recursion. Is there any other trick or algorithm for this??
- ajrules2105 March 10, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Trees and Graphs - 4of 4 votes
AnswersWAP a program to find a contineous subset whose sum is divisible by 7. We are given a array of number (negative+positive).
- yogi.rulzz October 26, 2013 in India
calculate the complexity of your algorithm| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 4of 4 votes
AnswersGiven three arrays A,B,C containing unsorted numbers. Find three numbers a, b, c from each of array A, B, C such that |a-b|+|b-c| +|c-a| is minimum.
- Rahul Sharma September 16, 2015 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 4of 4 votes
AnswersCar parking problem. An array given represents actual order of cars need to be parked. Like for example order is 4,6,5,1,7,3,2,empty. If cars are parked in some order like empty,1,2,3,7,6,4,2. Some person needs to get them into correct order, list out all instructions to the person to get in correct order with least number of swaps.
- hulk April 16, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 4of 4 votes
AnswersSuppose you have to maintain the stock values of various companies during various periods and return minimum stock value of a particular company over a given period of time.what data structure is best for this.
- nishu November 07, 2013 in India| Report Duplicate | Flag | PURGE
Amazon Intern Data Structures - 4of 4 votes
AnswersThis is one of the interview questions during the Amazon SDE interview. Request your help in providing the solution.
- satish1987 August 12, 2015 in United States
Question - We are interested in building a special type of sequence. for a given number N, we want to arrange the numbers {1,1,2,2,3,3,... N,N} such that they have the following property.
For each number / in (1,N) there should be exactly / numbers between the first appearance of the number and the second appearance. Below example would clarify further.
Input:
A Single number N for which we want to produce the sequence.
Output:
A space separated list of sequence or NA if there is no possible sequence.
Example Input:
3
Example Output:
2 3 1 2 1 3
Explanation : There is 1 number between 1s(2). There are 2 numbers between the 2's(3 1 ). There are 3 numbers between the 3's(1 2 1 ).| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm