Amazon Interview Questions
- 2of 2 votes
AnswersYou are given an array of both negative and positive integers. You need to rearrange the array such that positive and negative numbers alternate. Also, the order should be same as previous array and only O(1) auxiliary space can be used and time complexity boundation O(n).
- peechus July 29, 2014 in United States
eg. -2 3 4 5 -1 -6 7 9 1
result – 3 -2 4 -1 5 -6 7 9 1.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
Answerswe have website having several web-pages. And also there are lot many user who are accessing the web-site.
- Rahul Sharma July 28, 2014 in India
say user 1 has access pattern : x->y->z->a->b->c->d->e->f
user 2 has access pattern : z->a->b->c->d
user 3 has access pattern : y->z->a->b->c->d
user 4 has access pattern : a->b->c->d
and list goes on for lot many users which are finite and numbered.
Now the question is we have to determine the top 3 most occurring k-Page-sequence.
for the above example result will be : (k=3) a->b->c , b->c->d , z->a->b.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 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 - 0of 0 votes
AnswersReverse the alternate level nodes of the binary tree.
- singhvivekpes June 25, 2014 in United States
a
/ \
b c
/ \ / \
d e f g
/ \ / \ / \ / \
h i j k l m n o
Modified tree:
a
/ \
c b
/ \ / \
d e f g
/ \ / \ / \ / \
o n m l k j i h| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersBase class is given you need to stop exposing the base class methods without touching the base class at all.
- hareendrareddy June 07, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Java - 0of 0 votes
AnswersWhat happens when you enter URL in browser.
- suresh June 07, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersWrite a program to convert a decimal number into binary your code should work on both big endian and small endian machine. U have given a variable which tell u whether machine is big endian or small endian
- suresh June 07, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersGiven a graph, if we were to print all nodes within k hops of a given node, which algorithm would we use, the answer to this was obviously a Breadth first search. He followed it up asking, if one were to use Depth first search instead to code this problem instead, one would encounter bloated running times for Graphs with certain attributes (Perhaps Dense graphs or some such). Describe what types of graphs would a DFS algorithm falter with and why.
- suresh June 07, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersGiven a floor of dimensions 2 x W and tiles of dimensions 2 x 1, write code to find the number of ways the floor can be tiled.
- suresh June 07, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 1of 1 vote
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:
- suresh June 07, 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 Algorithm - 1of 1 vote
AnswersPrint permutations of a string.
- Sugarcane_farmer June 01, 2014 in India
I started with the recursive answer. He asked me the complexity. (Had no idea). But is was large
Then he asked me, if i could optimise it. I said i could sense this can be done using DP. Could not get how to do it though.
I had quick perm code, but dint understand it(saw it night prev to interview) so dint answer that.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
Answersimplement bool isFactorialDivisible( int x, int y)
- suresh June 01, 2014 in India
Return true if x! is divisible by y
else return false| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersGiven a continuous stream of strings, maintain strings such that duplicate are eliminated on the fly. The interviewer wanted working code. So coded the solution during the interview and emailed it to him 10 mins after.
- suresh June 01, 2014 in India
So if you get “Ted”, “John”, “Mark”, “Ted”, “David”, at the moment in
time, the list should contain John, Mark, David| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 2 votes
AnswersUse smart ways to find prime factors and then arrive at the result for large A & B in input. Bruteforce won't work.
- avinash.it09 May 31, 2014 in United States
Given A,B print the number of pairs (a,b) such that GCD(a,b)=1 and 1<=a<=A and 1<=b<=B.
Input:
First line contains an integer T, the number of testcases. Each of next T lines contains two space separated integers denoting Aand B.
Output:
Output T lines, each containing single integer, the required output for each test-case.
Constraints:
1 <= T <= 10
1 <= A <= 10^5
1 <= B <= 10^5
Sample Input (Plaintext Link)
1
3 2
Sample Output (Plaintext Link)
5
Explanation
1,1
1,2
2,1
3,1
3,2
Time Limit5 sec(s) (Time limit is for each input file.)
Memory Limit256 MB
Source Limit1024 KB| Report Duplicate | Flag | PURGE
Amazon SDE1 - 1of 1 vote
AnswersYou have given M array each of size n all array are sorted separately write a program to make a big sorted array of size m*n . during discussion he told me to prove many lemma like height of tree is log(n)( for n elements) sum of n natural number is (n*n+1)/2 and many more. He modified problem many times don’t use extra space do it in space etc.
- suresh May 22, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 1of 1 vote
AnswersWrite a program to convert a decimal number into binary your code should work on both big endian and small endian machine. U have given a variable which tell u whether machine is big endian or small endian
- suresh May 22, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersU have given 10 files and you have given a string suggest data structure which ll facilitate efficient search of string in the file if string appears more than ones in that case u have to print line number and file in which they appear.
- suresh May 22, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 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 - 0of 0 votes
AnswersYou are given very huge file , with each line containing a single word. We have to give the count and word which is repeated most. I answer of using TRIE data structure to hold the word. I am reading a word at a time and incrementing the counter if i am getting the same word. I am keeping a global max count to keep the max count and the word. Complexity will be O(total letters in the file);
- ur.devesh May 16, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersGiven a binary search tree (BST) with each node having some value. You have to compute for each node the summation of all nodes whose value is greater than the current node.I have used the DFS kind of algorithm.
- ur.devesh May 16, 2014 in United StatesDictionary<node,bool> visited = new Dictionary<node,bool>(); int Traverse(node n ) { if(node.Right == null) if(node.Left != null && !visited(node.Left)) Traverse(node.Left); return node.value; node.Summation = Traverse(node.Right); if(node.Left != null && !visited(node.Left)) Traverse(node.Left); return node.Value + node.Summation; }
| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersProvided a number dictionary and a number, x , which is formed from the number dictionary. Find the rank of the number x? Rank is defined as the position of the number x when all the number formed from the dictionary are sorted.
- ASimpleCoder May 10, 2014 in India
Example
Input :{4,1,5}
X : 451
Output : 4
(145,154,415,451,514,541). 451 comes at 4th position| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
Answerswrite a program to generate random numbers without using the in-built functions?
- vrajendra.singh.mandloi May 02, 2014 in india| 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
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 - 0of 2 votes
Answersgiven a N x N matrix find the no. of times a word is present in that matrix. constraints you can move in 3 directions from one cell 1. forward , 2. down 3. diagonal . Find all teh occurance of all the word
- GOOGLE_SDE April 15, 2014 in United States
forward means right (x+1,y)
down mean (x,y+1)
diagonal means (x+1,y+1)
it can be done with BFS. {search the no. of occurance of a given word example "sachin" in the whole NxN matrix}
w | s | r | t | g | g|
a | a | c | h | i | n |
k | c | h | u | j | j |
o | h | i | n | y | q |
in this sachin can be found out 3 times.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 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