Amazon Interview Questions
- -1of 1 vote
Answersconsider a battlefield to be made up of square cells of unit dimensions. a soldier on the battlefield can move from a cell to all(8) of it's neighboring cells. soldier has a gun with with him which he can shoot the targets up to any distance along any of the 8 possible directions (north,east,west,south,north-east,north- west,south- east,south- west). also some sell are bulletproof which prevents bullets to pass but soldier can walk over them as if it were a normal cell.he can destroy the target from a bulletproof cell but not from a cell behind it.
- sarath.chalasani46 May 03, 2015 in India for dev
position of a target/ soldier can be given by the cell, they are on.given the position of the target, starting position of a target and position of all the bullet proof cells. you have to tell the position of closest shooting point i.e the cell from which, the soldier can shoot the target and is closest to the starting position of the soldier. if there are more than such cells, output all of them.
Input/output specifications :
Input specifications :
I) size of the battlefield { integer pair (N,M) : battlefield will be of N*M size )
II) staring position of the soldier {integer pair (i,j)}
III) position of the target {integer pair (x,y) : position of the cell on which target is mounted}
IV) position of the all bullet proof cells { list of integer pair a#b : each element in the list is a position of bullet proof cells }
output specifications :
sequential list of integer pair i#j (cell) that are closest shoot points and must fallow row wise traversal.
Note: if the output list contains four shoot points : (2,1), (1,2), (3,2), (2,4) on a 4x4 battle field.
then the correct output will be {1#2,2#1,2#4,3#2} not {1#2,2#1,3#2,2#4}
Examples:
Input : {2,2} {2,1} {2,2} {1#1,1#2}
output : 2#1
below is the method signature in java:
public static String[] nearest_shoot_point(int[] input1,int[] input2,int[] input3String[] input4){
}| Report Duplicate | Flag | PURGE
Amazon Developer Program Engineer Java - 3of 3 votes
AnswersThere are N pots. Every pots have some water in it. They may be partially filled. So there is a Overflow Number 0 associated with every pot which tell how many minimum stone pieces are require for that pot to overflow. So if for a pot 0-value is 5 it means minimum 5 stone pieces should be put in that pot to make it overflow. Initially a crow watched those pots and by seeing the water level he anticipated 0-value correctly for every pot ( that is he knew 01 to On). But when he came back in evening he found that every pot is painted from outside and he is not able to know which pot has what 0-value. Crow wants some K pots to overflow so that he can serve his child appropriately. For overflow of pots he need to search for stone in forest( assume that every stone has same size). He wants to use minimum number of stones required to overflow K pots. But only he know the 0-value of pots he doesn't know now which pot has what 0-value. So the task is that in what minimum number of stones he can make K pots overflow in worst case.
- veeru April 29, 2015 in India for Development
Input/Output Specifications Input Specification: 1) A array 0 corresponding to 0-value of N pots {01, 02, On} 2) Number of pots 3) K -value ( number of pots which the crow wants to overflow}
Output Specification: Minimum number of stones required to make K pots overflow in worst case. Or -1 if input is invalid
Example: Let say there are two pots pot 1 has 0 value of 5 , 01= 5 pot 2 has 0 value of 58, 02= 58 Let say crow wants to make one of the pot to overflow. If he know which pot has what 0-value he would simple search for 5 stones and put then in pot 1 to make it overflow. But in real case he doesn't know which pot has what 0-value so just 5 stones may not always work. However he does know that one pot has 0-value S and other has 58. So even in worst case he can make one of the pot overflow just by using 10 stones. He would put 5 stones in one pot if it doesn't overflow he would try the remaining 5 in the other pot which would definitely overflow because one of the pot has 0-value of 5. So the answer for above question is minimum 10 stones even in worst case. Input : Input 1= {5,58} Input 2= 2 Input 3= 1 Output : 10| Report Duplicate | Flag | PURGE
Amazon Software Engineer - 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 - 1of 1 vote
AnswersImplement a program to reverse the linear linked list in pairs. it should handle both even number of nodes and odd number of nodes. if odd number of nodes, the last node will be the last node after reversion.
- panchadi520 April 27, 2015 in India
Do not move the data in the nodes. Do manipulate node pointers/references. the nodes themselves need to be manipulated, not just the data in the nodes.
For example, if the initial linear linked is,
1->2->3->4->5
after reverse it should be,
2->1->4->3->5| Report Duplicate | Flag | PURGE
Amazon Senior Software Development Engineer Data Structures - 1of 1 vote
AnswersImplement a function that checks if the given binary tree is binary search tree(BST). Use tree operations to solve this. do not try solving by pre-order traversal of the tree and then checking if the array is sorted.
- panchadi520 April 27, 2015 in India
instead, traverse the tree for checking if it is BST.| Report Duplicate | Flag | PURGE
Amazon Senior Software Development Engineer Data Structures - 0of 2 votes
AnswersWrite a function that takes two arguments one array of integers that ranges between 0 and 9 and second the target sum(again integer). It produces all permutations strings of the input digits that equals the target sum.
- panchadi520 April 27, 2015 in India
For example, if input is array 2, 3, 5 and target sum is 10, then the output should be:
22222 because 2+2+2+2+2 = ,10
2323 as 2+3+2+3 = 10
3232
55
2233
3322
532
235
352
etc.,| Report Duplicate | Flag | PURGE
Amazon Senior Software Development Engineer Data Structures - 1of 1 vote
AnswersThere are discounts on particular time period
- Dinesh Pant April 26, 2015 in India
suppost
Day1 - Day5 => 10%
Day2 - Day 8 => 5%
Day4 - Day6 => 20 %
find the period where maximum discounts is available.
For above example the period is Day4 - Day5 => 10+5+20
that means 35%
Provide the generalize solution. Period can be time also.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 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 - 0of 0 votes
Answersgiven an array with elements check if just by exchanging two elements of the array we get a sorted array.
- sandeep.nie April 22, 2015 in United States
time restriction:
O(NlogN)
space restriction: 2N| Report Duplicate | Flag | PURGE
Amazon Software Developer Arrays - 0of 0 votes
AnswersAssuming you have a binary tree which stores integers, count the number of nodes whose value is lower than the value of its upper nodes.
- sandeep.nie April 22, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon Software Developer Algorithm Trees and Graphs - 1of 1 vote
AnswersWe've 1 book left in the inventory. and two people are trying to get the same book ( say person x and person y ). Person x has added book to the cart and about to make payment and person y has also added book to the cart. How would you solve this concurrency problem ?
- the-awakened-1 April 22, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon System Design - 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 - 3of 3 votes
AnswersGiven two binary numbers each represented as a string write a method that sums up the binary numbers and returns a result in the form of binary number represented as a string. You may assume that input fits in the memory and the input strings are, in general, of different length. Optimize your solution, do not use unnecessary 'if' branching.
example:sumBinary('0111101', '1101')
returns
- autoboli April 21, 2015 in United States
'1001010'| Report Duplicate | Flag | PURGE
Amazon - -1of 1 vote
AnswersHardest bug you faced
- danny April 17, 2015 in United States for Amazon Music| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Behavioral - 3of 3 votes
AnswersLet's assume that there's an array that has nonzero natural numbers where all the numbers repeat an even number of times, except for one value that repeats an odd number of times. Can you write me a function that takes this array, and returns the value that occurs the odd number of times?
- danny April 17, 2015 in United States for Amazon Music
Ex : - [ 4, 7, 2, 2, 5, 3, 5, 7, 7, 3, 4, 5 ]| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersThere is a data structure called mySruct and it contains a, b , c all three of type int . Which means that any data structure takes up 12 bytes . Then in the main define an array of 3 myStructs (ie taking up 36 bytes .. ) . Then define char * and make him an assignment to array( with casting ) . Then do
- Stella April 15, 2015 in United States
16 = + c * . That is, come to b in second myStruct. Then do c = 10 , and ask what 's going on?
So the answer is that arr [0] -> b becomes 10| Report Duplicate | Flag | PURGE
Amazon Jr. Software Engineer - 0of 0 votes
AnswersFind the longest running positive sequence in an array -
- coderhacker April 15, 2015 in United States
Eg - [1,2,-3,2,3,4,-6,1,2,3,4,5,-8,5,6]
It should return 5, with start index : 8| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Arrays - 0of 0 votes
Answersclass a{
- emcho.coh April 12, 2015 in United States
public int x=7;
public int y=9;
void f1(){x=24;}
void static f2(){y=35;}
}
what problem in the code?
what is need to change in the code for compaling?| Report Duplicate | Flag | PURGE
Amazon Jr. Software Engineer - 1of 1 vote
AnswersFind the second most repeating number in an array without using extra storage. (I had given solution using a hash table)
- xyz_coder April 02, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon Intern - 0of 0 votes
AnswersImplement a stack that supports push, pop and median (the one from statistics) operation in the most efficient way
- xyz_coder April 02, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon Intern - 1of 1 vote
AnswersImplement a stack that supports push, pop and mode(the one from statistics) operation in the most efficient way
- xyz_coder April 02, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon Intern - 0of 2 votes
AnswersWrite a program to test whether a string and all strings that can be made using the characters of that string are palindrome or not.
- umang.agrawal91 April 02, 2015 in United States
Eg:
Input Output
mmo True
yakak True
travel False
Note : Please do not use any inbuilt functions.| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Coding - 0of 0 votes
AnswersGiven an array of ints, return a string identifying the range of numbers
- tbag March 31, 2015 in United States
Example
Input arr - [0 1 2 7 21 22 1098 1099]
Output - "0-2,7,21-22,1098-1099"| Report Duplicate | Flag | PURGE
Amazon Software Engineer Algorithm - 4of 4 votes
AnswersSparse number is an integer if there are no adjacent 1 in it's binary representation.
- Rahul Sharma March 30, 2015 in United States
Like: 5 -> 101 (no adjacent 1)
9 -> 1001 (no adjacent 1)
while 6-> 110 is not sparse number.
Now you are given an integer find the NEXT BIGGER sparse number.Please mind 'it is next bigger'.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Coding - 1of 1 vote
AnswersGraph problem:
- manidam07 March 30, 2015 in India
Critical node: If a node reaches another node only through one node.
Eg: A-C-B and A-E-B are critical nodes. (A reach B through one node which is C or E)
If A reaches B through more than one node, then they are not critical nodes.
1) A-C-B
A-D-E-B (A reach B thro C which might lead to critical node but A has another path to B thro D and E, so they are not critical nodes).
2) X-Y-Z
X-A-Z (X and Z are critical nodes)
Now find all critical nodes.| Report Duplicate | Flag | PURGE
Amazon Developer Program Engineer Algorithm - 0of 0 votes
AnswersGiven two sorted LinkedLists, merge them into one sorted LinkedList
- owasserman2012@my.fit.edu March 27, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer Intern - 0of 0 votes
AnswerHashmap(what is it, time complexity of insertion and deletion)
- owasserman2012@my.fit.edu March 27, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer Intern - 0of 0 votes
AnswersYou are to concatenate n strings (concatenate in any order) and a function:
- alanturing06022014 March 22, 2015 in United States
int strCat(str1, str2); // returns the concatenated str length
Concatenate all strings in any order so that total cost is minimum.
Example: Strings A="abc", B="wxyz", C="a"
Cost of strCat(A,B) = (3+4) = 7
Cost of strCat(AB,C) = 7+1 = 8
Total cost = 7+8 =15
Other way:
Cost of strCat (A,C) = 3+1 = 4,
Cost of strCat (AC,B) = 4+4 = 8
Total Cost = 4+8 = 12
In this case, min(12,15) = 12 so Ans=12.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm