## Amazon Interview Questions

- 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 - 0of 0 votes

AnswersHow to remove file named "~" ?

- Pinky August 09, 2014 in India for ECOX| Report Duplicate | Flag | PURGE

Amazon SDE1 Unix - 2of 2 votes

AnswersGiven a file containing a list of ip addresses that have lost their dots(.'s), write a program to find the ip addresses, assume ipv4. input: 11111 output. 1.1.1.11, 11.1.1.1, etc

- rk August 09, 2014 in United States| Report Duplicate | Flag | PURGE

Amazon SDE1 - 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 ﬁnite, 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 ﬁnding 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 States`Dictionary<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

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window