Amazon Interview Questions
- 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 - 0of 0 votes
AnswersGiven a value (in double) return its square root.
- wolfengineer June 06, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven a List of Students that are already sorted based on names, write a function to return list of students that is sorted based on grade (four possible grades are a,b,c and d). If two students has same grade, they should be sorted internally based on name.
I have written a code based on bucket sort. Something like this. Not sure whether this is optimal.
- dumUser June 06, 2014 in United Statespublic List<Student> sortByGrade(List<Student> students) { List<Student> aGradeStudents = new LinkedList<Student>(); List<Student> bGradeStudents = new LinkedList<Student>(); List<Student> cGradeStudents = new LinkedList<Student>(); List<Student> dGradeStudents = new LinkedList<Student>(); for(Student st : students) { switch(st.getGrade()) { case 'a' : aGradeStudents.add(st); break; case 'b' : bGradeStudents.add(st); break; case 'c' : cGradeStudents.add(st); break; case 'd' : dGradeStudents.add(st); break; }; } List<Student> sortedStudents = new LinkedList<Student>(); sortedStudents.addAll(aGradeSudents); sortedStudents.addAll(bGradeSudents); sortedStudents.addAll(cGradeSudents); sortedStudents.addAll(dGradeSudents); }
| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 1of 1 vote
AnswersGiven an array of sorted numbers, find the index of first occurrence of the given number.
- dumUser June 06, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
Answershow to use perl to write a script to deal with the comments in a C++ file?
- holmespanda June 06, 2014 in United States
let's say a file a.cpp, and it contains several comments. You have to remove the comments.
we know that in C++ there two kinds of comments // and /* */
i was trying to use the regex, but later i was stuck when i found that these comments can appear in a string, say "aaa // bbb", then it will be another situation.
can someone help me with this case?
any ideas will be helpful.| Report Duplicate | Flag | PURGE
Amazon Principal Software Engineer Perl - 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 - 2of 2 votes
AnswersWrite a function, for a given number, print out all possible way to make up that number eg: 2 - 1 1,2
- sLion May 25, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
AnswersYou are given a 2D grid in which each cell is either empty, contains an entry “D” which stands for Door, or an entry “W” which stands for wall (Obstacle). You can move in any of the four directions from each empty position in the grid. Of course you cannot move into a cell that has “W” in it. You need to fill each empty cell with a number that represents the distance of the closest door to that cell.
- Nascent May 24, 2014 in India| Report Duplicate | Flag | PURGE
Amazon - 0of 0 votes
AnswersA furniture can be made of material like metal, wood, .... Also there are different furniture types chair, table, sofa. A wood furniture should be tested against choaking. metal furniture is tested against fire, etc. Design these in OOAD.
- geekyjaks May 24, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE-2 Object Oriented Design - 0of 0 votes
AnswersThere are N nodes. Each node has a non negative integer value. Define a optimistic algorithm which ensures that all node has all other node's value.
- geekyjaks May 24, 2014 in India
Constraint: While a node is sending data to another data, it can't receive data, vice versa.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - -1of 1 vote
AnswersWrite code to read from a file and build datastructure that helps you query products based on their category, title, author etc.
- LV May 22, 2014 in United States
ItemNo , Product No (unique), Title, Author, Category
1 , 00000001, Cracking Coding Interview, Gayle Laakmann McDowell , Books > Business, Finance & Law > Careers > Job Hunting
2 , 000002, The Art of Captaincy, Robert James, Books > Biography > Sport > Cricket| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Data Structures - 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
AnswersWrite a test case for the Amazon App store.
- nullmodem May 16, 2014 in United States
Since there are so many functionality in Amazon App store, do I just make a smoke test or do I need to go all out and make testcase that will cover everything.| Report Duplicate | Flag | PURGE
Amazon Testing / Quality Assurance - 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 - 6of 6 votes
AnswersGiven a array int a[]={2,5,1,9,3,7,2,8,9,3} and the no. of swap operations.We are allowed to do swap operations.
swap constraint: exchange only adjacent element.
Find the max number that can be formed using swap operations.
- koustav.adorable May 11, 2014 in Indiapublic static int[] maximize(int arr[],int swapsAllowed);
| Report Duplicate | Flag | PURGE
Amazon Web Developer Coding - 1of 1 vote
AnswersFind the largest sequence in a array which sums to zero
- ASimpleCoder May 10, 2014 in India| Report Duplicate | Flag | PURGE
Amazon - 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 - 1of 1 vote
AnswersGiven a mathematical expression, remove the redundant brackets from the expression.
- !@# May 08, 2014 in Indiae.g. input: (a + (b*c)) * (d * ( f * j) ) output should be: (a + b * c) *d * f * J
| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Stacks - 1of 1 vote
AnswersImplement LRU cache of size 10 which can store Key, Value pair. (get(key) & put(key,value) methods)
- Miral Patel May 07, 2014 in United States
- If we try to add 11th element, the least recently used element should get removed.
- If key already present, overwrite it and mark it as most recently used.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Data Structures - 0of 0 votes
AnswersYou are given an array of N elements. Each element in the range Min of int to Max of Int. You need to find the length of longest sequence in this array such that difference of largest and smallest element of that sequence is 1. The sequence need not be sequential.
- northernlight May 06, 2014 in United Kingdom
For e.g. array[]={6,10,6,7,8,9,0}
seq {6,10} = diff is 4 len 2
seq { 10,7,8} diff is 3 len 3
seq { 7,8,9} diff 2 len 3
seq {6,6,7} diff is 1 len 3
In this example the program should return 3 .
Complexity N*longN| Report Duplicate | Flag | PURGE
Amazon Algorithm Arrays C C++ - -2of 2 votes
AnswersGiven 4 bottles out of which one is of less weight. Find out the defective one by weighing only once.
- Nascent May 04, 2014 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer