Amazon Interview Questions
- 0of 0 votes
AnswersGiven a Binary Tree (not BST) with integer values . 1) Find path from root to any node with max sum. 2) As there can be many path's find all of them. 3) Print all such paths.
- singhsourabh90 January 18, 2013 in India
Do this in O(n) : n is number of node's in tree. he wanted an O(n) solution not O(n)+O(n) ie. u can't traverse tree twice .| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
Answersgiven arr1 = {5,6,4,2,2} arr2={4,2,2,1}
- Minnu December 27, 2012 in United States
return common elements {4,2,2}| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 0of 0 votes
AnswersGiven a million points (x, y), give a O(n) solution to find 100 points closest to (0, 0).
- Illusion November 25, 2012 in United States| Report Duplicate | Flag | PURGE
Amazon Algorithm - 0of 0 votes
AnswersWrite a function that given a Binary tree, can find out if its a Binary Search Tree
- mlm09k October 02, 2012 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven a array, find the largest contiguous sub-array having its sum equal to N. ( optimal solution only)
- sam August 28, 2012 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven the Pre-order of the BST .check if each non-leaf node has only one child.Linear Time is expected.
- grave July 31, 2012 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Trees and Graphs - 0of 0 votes
AnswersYou have been given three arrays A,B and C.
- Ajax May 21, 2012 in India
You have to find out all the elements in A and B such that the A[i]-B[j]=C[k]| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven an unsorted array of numbers. Find if the array consists of consecutive numbers after sorting. Do this in linear time.
- Anonymous March 15, 2011
Example 1: If array has 5,2,3,1,4
after sorting we get 1,2,3,4,5 which represents consecutive numbers
Counter Example:
If the array has 34,23,52,12,3 after sorting we get 3,12,23,34,52 which are not consecutive| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersThere are two poles of equal height 15mts. One cable with length 16mts is hanging between that two poles. The height from center of the cable to earth is 7mts then what is the distance between that two poles.
- coolGuy March 04, 2011
How to solve this ?| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Brain Teasers - 0of 0 votes
AnswersGiven an integer array of which both first half and second half are sorted. Write a function to merge the two parts to create one single sorted array in place [do not use any extra space].
- coder November 01, 2010
e.g. If input array is [1,3,6,8,-5,-2,3,8] It should be converted to: [-5,-2,1,3,3,6,8,8]| Report Duplicate | Flag | PURGE
Amazon Developer Program Engineer Coding - 0of 0 votes
AnswersAlgo to check if given binary tree is binary search tree or not. Code it and return true or false. Also it should find the number of nodes in the tree irrespective if the tree is BST or not.
- AnonymousUser March 28, 2010| Report Duplicate | Flag | PURGE
Amazon Microsoft Software Engineer / Developer Trees and Graphs - 0of 0 votes
AnswersGiven an array of integers where some numbers repeat 1 time, some numbers repeat 2 times and only one number repeats 3 times, how do you find the number that repeat 3 times. Using hash was not allowed
- Anonymous March 08, 2010| Report Duplicate | Flag | PURGE
Amazon Google Software Engineer / Developer Algorithm - 0of 0 votes
AnswersSaw this question in one of the algo communities.
- Vaishnavi November 29, 2009
Amazon telephonic interview question on Matrix
Input is a matrix of size n x m of 0's and 1's. eg:
1 0 0 1
0 0 1 0
0 0 0 0
If a location has 1; make all the elements of that row and column = 1. eg
1 1 1 1
1 1 1 1
1 0 1 1
Solution should be with Time complexity = O(n*m) and space complexity = O(1)| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven an array , find the element (say X) that has all the elements less that it to its left side and all the elements greater to it on its right side.
- nidhi.prakash.410 January 23, 2017 in India
The left and right elements of X need not be in sorted form.| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer - 1of 1 vote
Answerscreate palindrome in javascript, by appending a minimum set of characters at the end.. eg. test => testset
- codebind December 19, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer - 3of 3 votes
AnswersPrint the level of friendship.
- AnonD June 24, 2015 in United States
Given a person and list of his friends, print all his friends by level of association.
The text file will be like one below
A: B,C,D
D: B,E,F
E: C,F,G
If the input is A, the out put should be:
Level 1 - B,C,D
Level 2 - E,F
Level 3 - G| Report Duplicate | Flag | PURGE
Amazon Software Engineer Algorithm - 0of 0 votes
AnswersSuppose you have an array with infinite numbers, which is sorted and there may be duplicates. Find the occurrence of a number.
- MM February 20, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersThere are 8 statues 0,1,2,3,4,5,6,7 . Each statue is pointing in one of the following four direction North, South, East or West.
- viksolanram4 August 18, 2014 in United States
John would like to arrange the statues so that they all point in same direction. However John is restricted to the following 8 moves which correspond to rotation each statue listed 90 degrees clockwise. (N to E, E to S, S to W, W to N)
Move A: 0,1
B: 0,1,2
C: 1,4,5,6
D: 2,5
E: 3,5
F: 3,7
G: 5,7
H: 6,7
Help John figure out fewest number of moves to help point all statues in one direction.
Input : A string initialpos consisting of 8 chars. Each char is either 'N,'S,'E,'W'
Output: An integer which represents fewest no. of moves needed to arrange statues in same direction. If no sequence possible then return -1.
Sample test cases:
input: SSSSSSSS
Output: 0
Explanation: All statues point in same direction. So it takes 0 moves
Test case 1:
Input : WWNNNNNN
Output: 1
Exp: John can use Move A which will make all statues point to North
Test Case 3:
input: NNSEWSWN
Output: 6
Exp: John uses Move A twice, B once, F twice, G once. This will result in all statues facing W.
Note: Read input from stdin and output from stdout| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 1of 1 vote
AnswersYou have an array like ar[]= {1,3,2,4,5,4,2}. You need to create
- gdg June 21, 2014 in United States
another array ar_low[] such that ar_low = number of elements lower
than or equal to ar in ar[i+1:n-1].
So the output of above should be {0,2,1,2,2,1,0}
Time complexity : O(nlogn)
use of extra space allowed.| Report Duplicate | Flag | PURGE
Amazon - 1of 1 vote
AnswersGiven a huge file 100 million integers. He further divided the file into 100 files with 1 million integers in each and each file is sorted. Needed to find the k smallest integers.
- pulkit.mehra.001 April 07, 2014 in India
I used the concept of min-heap. Take the first element from each file and construct a min-heap. Take the root,as it is the smallest element and insert the next element from the file which contains the root root element. Heapify the tree and repeat k times.
The interviewer asked if another efficient method exists?| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 3of 3 votes
AnswersGiven a set of intervals like 5-10, 5-10, 8-12, 9-15
- blackfever April 03, 2014 in India
Find the ith smallest number in these intervals.
for eg:-
Suppose we have intervals like 5-10, 8-12.
Then total numbers in these two intervals would be: {5,6,7,8,8,9,9,10,10,11,12}
So, 1st smallest number: 5
4th smallest number: 8
5th smallest number: 8 (here is the
change since now we have duplicate elements also) and so on.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 2of 2 votes
AnswersThere is a large file( 1TB) containinig braces. Question is to check for their balance. I said will use a counter, will increment on an open brace and decrement on an close brace. If counter goes negative or counter is non zero at the end of the file, braces are not balanced. Otherwise balanced. Followup question was to make this process parallel ( meaning to see if this problem can be solved through parallelism, like dividing the the problem into sub problem....) Remember the file is very large.
- gns January 23, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Problem Solving - 3of 3 votes
AnswersSuppose you are supplied with a file containing a list of words like ABC, BCD , CAB ( say each word in new line ). now you have to suggest algorithm for this problem -
- ajitpec November 21, 2013 in India
When a user type some character, we have to suggest him next character and basis of suggestion is that the character you are going to suggest should have maximum occurrence at that position among all these words.
For example , Let's say words are
ABC
BCD
CBA
Now if user types 'A' we have to suggest him 'B' as next character because if you see at second position in all words 'B' is occurring most number of times ( 2 times ).
similarly if he types 'AB' then we need to suggest him third character as 'C' as in third index all words have same occurrence but 'C' comes first.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Data Structures - 2of 2 votes
Answersc program to find square root of an interger without using in built functions
- saran August 12, 2013 in India| Report Duplicate | Flag | PURGE
Amazon Intern C - 2of 2 votes
AnswersOutput the leftmost element of each level of a tree
- 3139a1m August 01, 2013 in India| Report Duplicate | Flag | PURGE
Amazon Intern