Amazon Interview Questions
- 0of 0 votes
AnswersGiven a community of people, find out a person who could be a potential mayor. Constraints as below.
- AVK September 22, 2013 in United States
1) Mayor does not know any of the people in the community.
2) All the people in the community must know the mayor, that is he has to popular.
My apologies, I forgot to mention that the interviewer had also given me a function called " knows(int a, int b) " that returns a boolean value if a knows b.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 1of 1 vote
Answersgiven a binary tree ,find the largest sub-tree which is a BST...(largest means subtree having largest no of nodes in it)...this is a wonderful question.....
- psp.reachable@gmail.com October 13, 2008| Report Duplicate | Flag | PURGE
Amazon Development Support Engineer Trees and Graphs - 1of 1 vote
AnswersReverse an array in subset of N. Example:
- Prashant May 22, 2016 in India for Kindle
input: Array = [1,2,3,4,5,6,7,8,9], N = 3
output: [3,2,1,6,5,4,9,8,7]| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer - 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 - 1of 0 votes
AnswersPrint a binary tree in zig zag way... that is:
- bindas September 01, 2008
......a.........
....b....c.......
..d...e...f...g..
.h.i.j.k.l.m.n.o.
should be printed as a-c-b-d-e-f-g-o-n-m-l-k-j-i-h
what data structure will u use for that?| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven an array of 0s and 1s, and k, Find the longest continuous streak of 1s after flipping k 0s to 1s.
- neer.1304 February 14, 2016 in United States
E.x array is {1,1,0,0,1,1,1,0,1,1}
k = 1 (which means we can flip âkâ one 0 to 1)
Answer: 6 (if we flip 0 at index 7, we get the longest continuous streak of 1s having length 6)| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
AnswersGiven a list of 'N' coins, their values being in an array A[], return the minimum number of coins required to sum to 'S'
- Aman August 15, 2012 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven a String - aaaabbbbcc, convert the given string in to a4b4c2 without using extra memory. ( Note that every character appears more than once in input string and the repeated characters are contiguous)
- Mike February 12, 2012 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven an array of integers where every int has exactly one duplicate except one,
- other January 30, 2006
find the number with odd occuring number.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Brain Teasers - 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 - 1of 1 vote
Answers
- BVarghese July 26, 2013 in United StatesSearch for an element in a matrix. Rows and columns of the matrix are sorted in ascending order. eg. matrix [1 14 25 35] [2 16 28 38] [5 20 28 40] [16 22 38 41] search for 38. The interviewer was looking for a solution better than O(n+m). He didn't want a solution which starts searching from the left bottom and go to right or above according to the key value to search. That solution has O(n+m) worst complexity, where n is row count and m is column count.
| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven you an array of 100 Elements with one number missing, how will you find the missing number?
- radibioinfo July 25, 2013 in United States
Array 1 to 100 with 55 missing.| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Arrays - 2of 2 votes
AnswersWrite a function which compress string AAACCCBBD to A3C3B2D
- kishore February 18, 2013 in United States| Report Duplicate | Flag | PURGE
Amazon Software Development Manager Algorithm - 0of 0 votes
AnswersIn given array of elements like [a1,a2,a3,..an,b1,b2,b3,..bn,c1,c2,c3,...cn] Write a program to merge them like [a1,b1,c1,a2,b2,c2,...an,bn,cn].
- masoom May 13, 2012 in India
PS: Do it without using extra memory
Sample Testcases:
Input #00:
{1,2,3,4,5,6,7,8,9,10,11,12}
Output #00:
{1,5,9,2,6,10,3,7,11,4,8,12}
Explanation:
Here as you can notice, the array is of the form
{a1,a2,a3,a4,b1,b2,b3,b4,c1,c2,c3,c4}| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Data Structures - 1of 1 vote
AnswersFind the substring of length 3 which is present in the reverse order from the string.
- swethas17 November 22, 2011 in United States
Ex: if the string is abcdcba (cba is the reverse of abc) so we should return cba.
And was asked to improve upon the complexity.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer String Manipulation - 3of 3 votes
AnswersThere are N pots. Every pots have some water in it. They may be partially filled. So there is a Overflow Number 0 associated with every pot which tell how many minimum stone pieces are require for that pot to overflow. So if for a pot 0-value is 5 it means minimum 5 stone pieces should be put in that pot to make it overflow. Initially a crow watched those pots and by seeing the water level he anticipated 0-value correctly for every pot ( that is he knew 01 to On). But when he came back in evening he found that every pot is painted from outside and he is not able to know which pot has what 0-value. Crow wants some K pots to overflow so that he can serve his child appropriately. For overflow of pots he need to search for stone in forest( assume that every stone has same size). He wants to use minimum number of stones required to overflow K pots. But only he know the 0-value of pots he doesn't know now which pot has what 0-value. So the task is that in what minimum number of stones he can make K pots overflow in worst case.
- veeru April 29, 2015 in India for Development
Input/Output Specifications Input Specification: 1) A array 0 corresponding to 0-value of N pots {01, 02, On} 2) Number of pots 3) K -value ( number of pots which the crow wants to overflow}
Output Specification: Minimum number of stones required to make K pots overflow in worst case. Or -1 if input is invalid
Example: Let say there are two pots pot 1 has 0 value of 5 , 01= 5 pot 2 has 0 value of 58, 02= 58 Let say crow wants to make one of the pot to overflow. If he know which pot has what 0-value he would simple search for 5 stones and put then in pot 1 to make it overflow. But in real case he doesn't know which pot has what 0-value so just 5 stones may not always work. However he does know that one pot has 0-value S and other has 58. So even in worst case he can make one of the pot overflow just by using 10 stones. He would put 5 stones in one pot if it doesn't overflow he would try the remaining 5 in the other pot which would definitely overflow because one of the pot has 0-value of 5. So the answer for above question is minimum 10 stones even in worst case. Input : Input 1= {5,58} Input 2= 2 Input 3= 1 Output : 10| Report Duplicate | Flag | PURGE
Amazon Software Engineer - 0of 0 votes
AnswersN*N matrix. contains only 0's and 1's.
- kb August 13, 2012 in India
every row is sorted in descending order.
find row containing maximum no of 1's. Efficient soln reqd.| Report Duplicate | Flag | PURGE
Adobe Amazon Algorithm Coding - 0of 0 votes
AnswersYou are given a string. You need to find the longest substring with unique characters in O(n) time
- DashDash May 26, 2012 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 12of 12 votes
AnswersGiven 2 arrays.Imagine you are making bst from each array.u need to tell whether 2 bsts will be identical or not without actually constructing the tree.
- bharat June 03, 2013 in India
Ex:
2 3 1
2 1 3
will construct the same tree
A1[]={2,1,3}
2
1 3
A2[]={2,3,1}
2
1 3| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 0of 0 votes
AnswersA string contains only 0's and 1's, like 001010, swapping is permitted only with adjacent elements. Find an efficient way so that all the zero's are in the begining and the one's in the end. So the resultant string becomes 000011.
- singh May 22, 2012 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersThere is an Array with positive and negative integers randomly distributed. find the maximum sum of a subset of this array. (subset could contain any number of elements but not the adjacent elements). Follow up, what is the complexity of your algo.
- HighLander May 06, 2011
You can use additional Datastructures if you want.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 3of 3 votes
AnswersGiven two binary numbers each represented as a string write a method that sums up the binary numbers and returns a result in the form of binary number represented as a string. You may assume that input fits in the memory and the input strings are, in general, of different length. Optimize your solution, do not use unnecessary 'if' branching.
example:sumBinary('0111101', '1101')
returns
- autoboli April 21, 2015 in United States
'1001010'| Report Duplicate | Flag | PURGE
Amazon - 0of 0 votes
AnswersGiven a number N, find the smallest 3 digits number such that product of its digits is equal to N.For example for N=100 , 3 digits number is 455.
- sam February 14, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 3of 5 votes
AnswersThere are N(0 to N-1) players each having at Max 'M' (0 to M-1) number of followers. You have to select minimum number of players so that the total followers must be equal to a given number 'K'.
I/P would be like,
first line contain N, M, K followed by N lines containing string of 0 or 1 s.t. for i'th line if j'th char is 1 it means j'th person follows player 'i'
For. eg.
- P3A July 18, 2013 in India3 6 5 111100 000100 000010 ans=2 ( select 0th and 2nd )
| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 1of 1 vote
AnswersSuppose that we have a sorted singly linked list with integer values. For example:
- snass005@ucr.edu February 05, 2013 in United States
1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7
We want to change the pointers of this linked list so that it becomes:
7->1->6->2->5->3->4
I did not have enough time left to finish my code and I could not think of a good solution.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 0of 0 votes
Answersgiven an integer find the next(smallest number greater than given number) integer which is palendrom
- getjar.com/todotasklist my android app November 17, 2011 in India
for ex 111 next palendrom 121
301 next palendrom 313| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm