Amazon Interview Questions
- 1of 1 vote
AnswersImplement a function that returns the i-th most popular item sold
- anom May 28, 2015 in United States
at xyz company. You cannot rely on any libraries.
Class Item {
String itemId;
int quantitySold;
}
/**
find the i-th most popular item in the list
**/
String find(List<Item> items, int i) {
// your code goes here
}| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Java - 1of 1 vote
AnswersTake a list of integers (left to right order) and return an integer of the number of identical binary trees that can be created from the same list.
- A. December 04, 2014 in United States
Input: [10, 8, 15, 6, 9, 4, 5]
Output: 24
Input: [12, 6, 19, 15, 5]
Output: 6
Input: [44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64]
Output: 1
I wrote a brute-force 'solution', creating a binary tree for each permutation of the list (with the same root as Input list) and compared each to the binary tree from the Input list. For large input lists (length > 10), my 'solution' is useless.| Report Duplicate | Flag | PURGE
Software Engineer Intern Problem Solving Amazon Algorithm - 1of 1 vote
AnswersGiven a multidimensional array like below:
0 1 0 0 3 0 3 3 0 0 0 0 0 0 2 0 0 1 0 2 0 0 0 0 0
"objects" are considered groups of numbers that touch along top, left, right, or bottom edges.
- Chris July 30, 2014 in United States
Find the number of objects.
For example given the above array, your code should detect 4 unique "Objects". {1,3,3}, {3}, {1}, and {2, 2}.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 1of 1 vote
AnswersFor a given array with positive and negative element, find sub array with maximum sum. Sub array must have same sequence of element as that of parental array.
- Razz April 26, 2014 in India
Eg: P = {4,6,-3,1,5,9,-2} then S ={4,6,-3,1,5,9} //Correct output.| Report Duplicate | Flag | PURGE
Amazon SDE-2 - 1of 1 vote
AnswersGiven a Text String T: abbbacctlkjlkcccaaabbb and pattern string P: ab[.]*c[.]*b, Find all occurances of P in T
- ssikka25 February 05, 2014 in United States for Amazon Prime| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 1of 1 vote
AnswersYou are given an array A with elements 0 to n-1, numbers can be repeated in the array. Create n sets where
- nirupam.astro January 05, 2014 in India
S[i]={a[i],a[a[i]],a[a[a[i]]]…}. Set has all elements unique. Find the size of the largest set.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 1of 1 vote
AnswersGiven 2 Arrays A and B, find the intersection of two arrays. Initially without using any other data structure. Later with using additional data structure.
- KSS March 09, 2012 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Arrays - 1of 1 vote
AnswersThere are n steps in a hill. You stand on the top, you can climb down either one step or two steps at a time. Find the number of paths by which you can reach the bottom?
- balarajesh.b December 17, 2011 in India for kindle| Report Duplicate | Flag | PURGE
Amazon Production Engineer Algorithm - 1of 1 vote
AnswersData structure used in parking lot.
- krithick.krishnagiri October 16, 2011 in -| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Data Structures - 1of 1 vote
AnswersFind intersection of two arrays
- Amazonview October 30, 2008| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Arrays - 1of 1 vote
AnswersIn a garden, there are several apples trees planted in a grid format. Each point (i,j) in the grid has |i| + |j| apples.
Allie can buy a square plot centred at (0,0). Find the minimum perimeter of the plot (1 unit having length = 1) such that she can collect at
least X apples. All plants on the perimeter of the plot are also included.
Sample:
- bertram_gilfoyle June 27, 2019 in IndiaInput = 1 Output = 8 input = 11 Output = 8 Input = 13 Output = 16
| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 1of 1 vote
AnswersWrite a method that can take in an unordered list of airport pairs visited during a trip, and return the list in order:
- mandy May 08, 2018 in United States
Unordered: ("ITO", "KOA"), ("ANC", "SEA"), ("LGA", "CDG"), ("KOA", "LGA"), ("PDX", "ITO"), ("SEA", "PDX")
Ordered: ("ANC", "SEA"), ("SEA", "PDX"), ("PDX", "ITO"), ("ITO", "KOA"), ("KOA", "LGA"), ("LGA", "CDG")| Report Duplicate | Flag | PURGE
Amazon Software Engineer - 1of 1 vote
Answersdown vote
- anony January 08, 2017 in India
favorite
Consider the following series:
A := 1
B := A*2 + 2
C := B*2 + 3 and so on...
Write a program that:
-outputs the number corresponding to a given letter;
-given a string of letters like 'GREP', computes the sum of the numbers corresponding to all the letters in the string (i.e., G + R + E + P), as given by the above series; and
-given a large number (that would fit into a standard 32-bit integer), finds the shortest string of letters corresponding to it. You may use a greedy approach for the last part. Compute the values of the numbers corresponding to letters as and when required and DO NOT pre-compute beforehand and store them in a data structure.| Report Duplicate | Flag | PURGE
Amazon Software Developer Algorithm - 1of 1 vote
AnswersThis is was asked in Amazon SDE online test from Hacker rank.
- sandeepparekh9 January 20, 2016 in Hong Kong
Initech is a company which has CEO Bill and a hierarchy of employees. Employees can have a list of other employees reporting to them, which can themselves have reports, and so on. An employee with at least one report is called a manager.
Please implement the closestCommonManager method to find the closest manager (i.e. farthest from the CEO) to two employees. You may assume that all employees eventually report up to the CEO.
Tree structure:
Bill -> Dom, Samir, Michael
Dom -> Bob, Peter, Porter
Peter -> Milton, Nina
Sample Data:
CEO Bill has 3 employees reporting to him: {Dom, Samir, Michael}
Dom has three reports { Peter, Bob, Porter}
Samir has no reports {}
Michael has no reports {}
Peter has 2 reports {Milton, Nina}
Bob has no reports {}
Porter has no reports {}
Milton has no reports {}
Nina has no reports {}
Sample calls:
closestCommonManager(Milton, Nina) = Peter
closestCommonManager(Nina, Porter) = Dom
closestCommonManager(Nina, Samir) = Bill
closestCommonManager(Peter, Nina) = Peter| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 1of 1 vote
AnswersSort a matrix such that rows in ascending order and columns should be in descending order.
- ritwik_pandey July 05, 2015 in India| Report Duplicate | Flag | PURGE
Amazon SDE-2 C++ - 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 - 1of 1 vote
AnswersAmazon wants to implement a new backup system, in which files are stored into data tapes. This new system must follow the following 2 rules:
- anca.grigoras88 February 16, 2015 in United States
1. Never place more than two files on the same tape.
2. Files cannot be split across multiple tapes.
It's guaranteed that all tapes have the same size and that they will always be able to store the largest file.
Every time this process is executed, we already know the size of each file, and the capacity of the tapes. Having that in mind, we want to design a system that is able to count how many tapes will be required to store the backup in the most efficient way.
The parameter of your function will be a structure that will contain the file sizes and the capacity of the tapes. You must return the minimum amount of tapes required to store the files.
Example:
Input: Tape Size = 100; Files: 70, 10, 20
Output: 2| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer 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 - 1of 1 vote
AnswersGiven a string, find the largest repetitive sequence. Algo + Code
- sameer.careercup April 02, 2014 in India
Ex: abcdefbcd – bcd, banana – ana| Report Duplicate | Flag | PURGE
Amazon Developer Program Engineer Algorithm - 1of 1 vote
AnswersGiven an input like:
[2, 4]
[1, 2]
[3, 6]
[1, 3]
[2, 5]
Use it to reconstruct this binary tree:1 2 3 4 5 6
Edit: The "1" is the root, I dont know why is aligning to the left
- eduardo.renshaw January 25, 2014 in United States for Seattle HQ
Note that:
a) The first number in each line is a parent.
b) Second number is a child.
c) The left child always shows up in the input before the right child.
Return root.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven a class with n people,where each people plays a game with all other people. Results are with you. You have to arrange them in a queue with a condition that, a[i] should have won a[i-1], for all I, you don’t need to care about a[i-2] . (a[i] may win or lose a[i-2]).
- mail.kshitij.jain October 09, 2013 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 1of 1 vote
AnswersFind if the given two trees can be joined leaf to leaf?
- beginner99 January 20, 2013 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Trees and Graphs - 1of 1 vote
AnswersGiven an array containing sequence of bits (0 or 1), you have to sort this array in the ascending order i.e. all 0' in first part of array followed by all 1's. The constraints is that you can swap only the adjacent elements in the array. Find the minimum number of swaps required to sort the given input array.
- Ankit October 29, 2012 in India
Example: Given the array (0,0,1,0,1,0,1,1) the minimum number of swaps is 3.
Note: You just need to complete the function given below for this task. The function is given a binary string as input and returns the required answer.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Arrays Data Structures Sorting - 1of 1 vote
AnswersGiven state of chess board, find whether its checkmate or not.
- sb September 10, 2012 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Application / UI Design - 1of 1 vote
AnswersGiven a binary search tree, design an algorithm which creates a linked list of all the nodes at each depth (eg, if you have a tree with depth D, you’ll have D linked lists).
- Algoseekar April 10, 2011
Algorithm:
1) Put the root node in stack.
2) put all the node in queue(say queue1) till stack is empty
3) Create another queue (say queue2) from values of queue1
4) Generate the link list from the values of queue1
5) Iterate over queue2 and put all the left and right child of queue2 in stack.
6) loop over step 2 to 5 till stack is empty.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven a MxN matrix, find the total number of possible paths from top-left to bottom-right element, you can go rightwards and downwards only.
- Anil March 26, 2011
Now, assume some of the entries in the matrix are blocked, find the number of such paths. For example: For a 3X3 matrix, total number of paths in first case is 6!/3!3! = 20.
For second case, if we block entry (2,2), we have only 2 paths available.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 1of 1 vote
AnswersAn array of integer of size N-1, all the elements are from range[1,N], one is missing, find it.
- myanything February 02, 2010| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Arrays - 1of 1 vote
AnswersWrite a function that returns true if the binary representation of an integer is a palindrome.
- maxxwizard May 03, 2017 in United States for Marketplace
9 = 1001 = palindrome
8 = 1000 = not palindrome| Report Duplicate | Flag | PURGE
Amazon SDE1 Java