Amazon Interview Questions
- 2of 2 votes
AnswersGiven two strings, return true if they are one edit away from each other, else return false. An edit is insert/replace/delete a character.
- codewarrior September 07, 2015 in United States
Ex. {"abc","ab"}->true, {"abc","adc"}->true, {"abc","cab"}->false| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersGiven a linked list and a positive integer n, reverse the order of nodes in between n and last but n nodes.
- codewarrior September 05, 2015 in United States
example: 1->2->3->4->5, n=2. Output is 1->4->3->2->5| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersGiven a postfix expression as a string, evaluate it and return the result. example : "423+*" ->20. The Postfix expression is well formed(need not check for bad expression)
- codewarrior September 05, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersFind the total number of connected components in a graph (there can be forests)
- codewarrior September 05, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 - 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 - 0of 0 votes
AnswersThere are n persons and k different type of dishes. Each person has some preference for each dish. Either he likes it or not. We need to feed all people. Every person should get atleast one dish of his chioce. What is the minimum number of different type of dishes we can order?
- prashant2006ster July 28, 2015 in India
Input is n x k matrix boolean matrix.For each person a row represent his likes or not likes each row.
n = 6 k = 7
1 0 0 0 1 0 0
1 0 0 0 0 1 0
1 0 0 0 0 0 1
0 1 0 0 1 0 0
0 0 1 0 0 1 0
0 0 0 1 0 0 1
Output
3
Explanation
Take dish number 5,6,7.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersOn a screen, there are multiple rectangles drawn, when a user clicks on any point, find the smallest rectangle enclosing this point.
- ritwik_pandey July 05, 2015 in India
I could not come up with a solution. The end points of rectangles were given and also the the point where the mouse was kept was given.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
Answersfind sum of longest increasing subsequence ?
- rahulkumar5july June 18, 2015 in India
Not the maximum sum,sum of longest subsequence.
Eg. 1, 8,2, 3
ans-> 6| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersGiven a N-ary Tree. Return true if it follows Sum Property otherwise false.
- chaturvediprerna03 June 17, 2015 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 2of 2 votes
AnswersGiven a sorted array with only 0's and 1's.Count the number of 0's.
- steelrahul June 16, 2015 in India for Hyderabad
e.g: 0 0 0 0 1 1
Ans: 4.| Report Duplicate | Flag | PURGE
Amazon SDE1 - 2of 2 votes
AnswersGiven n (of size m) Linked lists
- steelrahul June 16, 2015 in India for Hyderabad
Print all set(head of linked list) of link list that intersect with each other.
e.g.
1-->2-->3-->4-->5
6-->7-->8-->4-->5
8->9->10->11->12
13->14->15->12
16->17->18
1 6
8 13
16| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersGiven set of job schedules with start and end time, write a function that returns indexes of overlapping sets.
- Tom Walker May 13, 2015 in United States
for ex :-
input -> [1,2][5,6][1,5][7,8][1,6]
return -> [0,1,2,4]| Report Duplicate | Flag | PURGE
Amazon SDE1 - 1of 1 vote
AnswersWrite a function that accepts root of a binary tree and print zigzag level order traversal, each level print in new line.
- jaip42 May 10, 2015 in India for Kindle
For example,
Given tree:
1
2 3
4 5 6 7
8 9
output:
1
2 3
7 6 5 4
8 9| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 0of 0 votes
AnswersWrite a function that accepts root of a binary tree and return true if it is foldable otherwise return false. A binary tree is foldable if left subtree of root is mirror image if right subtree.
- jaip42 May 10, 2015 in India for Kindle
For example:
Given tree,
1
2 3
4 5 5 4
6 6
output: true| Report Duplicate | Flag | PURGE
Amazon SDE1 - 1of 1 vote
AnswersWrite a function that accepts root of a binary tree and return true if it is foldable otherwise return false. A binary tree is foldable if left subtree of root is mirror image if right subtree.
- jaip42 May 10, 2015 in India for Kindle
For example:
Given tree,
1
2 3
4 5 5 4
6 6
output: trus| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 1of 1 vote
AnswersWrite a function that accepts root of a binary tree and print zigzag level order traversal, each level print in new line.
- jaip42 May 10, 2015 in India for Kindle
For example,
Given tree:
1
2 3
4 5 6 7
8 9
output:
1
2 3
7 6 5 4
8 9| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 2of 2 votes
AnswersWrite a function that accepts two character arrays each represents a floating point number and return their sum in character array.
- jaip42 May 10, 2015 in India for Kindle
For example function accepts "23.45" and "2.5" and return their sum "25.95".
Restriction: We cannot use predefined functions / methods or parsing. We have to go with basic operations.| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 0of 2 votes
AnswersWrite code to rotate a square matrix:
- doomguy May 04, 2015 in United States
Input:
1 2 3
4 5 6
7 8 9
Output:
4 1 2
7 5 3
8 9 6| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 0of 0 votes
AnswersGiven a stairs of very large size. You are standing at the 0th step. You have to perform n actions. 1st action means you can move forward to 1 step or not. 2nd action is you can move 2steps or keep standing. 3rd action is you can move 3 steps or not and so on. Given is a step no. k which is broken. You can't stand on this step. Find out after performing n actions what can be the maximum no. of steps you can go.
- st2581ag10 April 27, 2015 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Puzzle - 0of 0 votes
AnswersGiven a binary tree populate the inorder successor of each node. Do it iteratively.
- firefox April 23, 2015 in India for Kindle| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
Answers{1, 1, 0, 0, 0},
- sunnyg522 April 22, 2015 in United States
{1, 1, 0, 0, 0},
{1, 0, 0, 1, 1},
{0, 0, 0, 0, 0},
{1, 0, 1, 0, 1}
write a function to return the size of max cluster and coordinate of it, max cluster size to the above example is 5.| Report Duplicate | Flag | PURGE
Amazon SDE1 Coding - 1of 1 vote
AnswersDesign a data structure to keep track of top k elements out of 2 billion records.
- panda April 22, 2015 in India
Each record is numberd with a key which is 30 bit and a number which is count of how many times the customer has visited us.
Come up with an data structure so that the updation of element in 2 billion records will be faster.
Getting top k element will be faster| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 0of 2 votes
AnswersGiven an array of random integers and a sum value, find two numbers from the array that sum up to the given sum.
- shoryagupta1493 March 12, 2015 in United States for Amazon Fresh
eg. array = {2,5,3,7,9,8}; sum = 11
output -> 2,9
Implement in O(n) time complexity. Find all distinct pairs. (2,9) and (9,2) are not distinct.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersWhat are the advantages of an array over a linked list? and vice versa.
- shoryagupta1493 March 12, 2015 in United States for Amazon Fresh| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 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 - 2of 2 votes
AnswersLink all the level order nodes to makes a linked list with the first node of each level acting as the root of that linklist.
- catlover February 27, 2015 in India
10
/ \
6 17
/ / \
4 14 19
So the Linklist will be
10->null
6->17->null
4->14->19->null| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersYou have three containers, small, medium and large. Passenger comes in, checkin the luggage. You have to store the baggage in the appropriate container and generate a unique token number. Then passenger should get back the bag using the same token number. Trick was if small container is full store in medium if available or large. Now if the large bag comes in and there is now a empty space in small, than move the small bag back to small & store the large bag. How to generate the unique token number and move the baagage internally without changing the token number?
- catlover February 27, 2015 in India
Lookup should be in constant time complexity and insertion in minimum complexity.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersYour are given two strings str1 and str2, you have to generate another unique string str3, which can only generated by these two string str1 and str2, no other string can generate that string str3. Some later point you have to retrieve back those two string str1 and str2 form that unique string str3.
- neelabhsingh February 20, 2015 in India for Hyderabad| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm