## Amazon Interview Questions

- 0of 0 votes
given a stream of natural numbers ,

and a array J contains integers in increasing orders

operations performed J = [2,3,4]

1 2 3 4 5 6 7 8 9 10…………..27....100...1111

first operation

J[0] = 2 => remove every 2nd integer

now the stream is

1 3 5 7 … 27

J[1] = 3

remove every 3rd

stream is now

1 3 7 …

3rd

given a natural number n , find if it will survive given J, or at what index it will

die.

- 0of 0 votes
Design OO food delivery app catering to use cases -

1) User can search different restaurant

2) User can select a restaurant

3) User sees a menu

4) Restaurant can change the menu any time

5) User adds an item from menu

6) User orders the food

7) User can track the order in real time

8) User can cancel the order

9) User pays for the order

- 0of 0 votes
Design food delivery app (OO design). Cater to use cases like search for different restaurants, selecting a restaurant, select an item from menu, menu can be updated in real time by restaurant, order the food, customer keeps track of the order in real time, payment for the order, cancel the order etc.

- 0of 0 votes
Design Uber low level OO design. Cater to use cases like search for a ride, different category of rides, select a ride, registration for a user and driver, paying for ride etc.

- 0of 0 votes
Find sum of n elements after kth smallest element in BST. Tree is very large, you are not allowed to traverse the tree.

- 0of 0 votes
There are Items[I1, I2, I3, I4] available in warehouses [W1, W2, W3, W4, W5] and serviceable by multiple partners with some shipping cost.

I1 available in W1

– serviceable by these partners S1[0.75 -shipping cost/selection cost], S2 [0.74], S3 [0.70]

available in W2

– serviceable by these partners S1[0.75], S2 [0.74], S3 [0.70]

available in W3

– serviceable by these partners S1[0.80], S2 [0.74], S3 [0.70]

I2 available in W4

– serviceable by these partners S2[0.85], S3 [0.94], S4[0.30]

available in W3

– serviceable by these partners S1[0.80], S2 [0.74], S3 [0.70]

I3 available in W1

– serviceable by these partners S1[0.85], S2 [0.55], S3 [0.70]

available in W2

– serviceable by these partners S1[0.80], S2 [0.54], S3 [0.70]

I4 available in W4

– serviceable by these partners S2 [0.74], S3 [0.70], S4[0.30]

available in W2

– serviceable by these partners S1[0.85], S2 [0.80], S3 [0.70]

available in W3

– serviceable by these partners S1[0.80], S2 [0.74], S3 [0.70]

You have to optimally select the items so that total cost will be minimum.

Ex: I can make a shipment from I1, I2, I4 fulfilled by W3 which will cost:

for partner S1: 2.40

for partner S2: 2.22

for partner S3: 2.10

Another Shipment I3 fulfilled by W2 which will cost: S2 [0.54]

Total cost: 2.10+0.54 = 2.64 with Shipment SH1 {I1,I2,I4} By S3 and SH2 {I3} by S2

Another possible way

I1, I3, I4 serviceable by W2 by Provider S2 : 2.08

I2 serviceable by W4 by S4: 0.30

Total cost: 2.38

So the shipments with minimum cost can be delivered/selected.

Write a program for the same to get optimum minimum cost for the number of shipments can be delivered from warehouses with shipping cost?

“If you ship multiple items in single packet, then the cost will be minimum. Assume Shipment Provider charges per packet and not on the weight and packing charges will be minimum. Idea is to consolidate/aggregate as many items as possible to one location so that packaging cost is minimum and on top of that you should consider warehouse selection cost.”

- 0of 0 votes
Q. Given an array of numbers. Print all the pairs (2) of numbers in the array if the sum of those numbers is also present in the array. Write in C

- 0of 0 votes
Design and implement traffic control system, also include pedestrian signal management as part of this solution.

- 1of 1 vote
Given a binary tree. I need to print the nodes in vertical line zigzag manner. For example: 1st vertical line from top to bottom, 2nd vertical line from bottom to top,3rd vertical line from top to bottom and so on

5

/ \

3 7

/ \ / \

1 4 6 8

/ \ \

2 9 10

Answer would be –

1

2 3

5 4 6

9 7

8

10

- 1of 1 vote
Given a binary tree and a target number, return whether or not there exist a path that can create target number. All inputs are integers. Target is not a string.

NOTE:: this is not path sums to target number

ex:

3

4 5

6 7 8 9

359 = return true

38 = return false

47 = return true

6 = return true

- 0of 0 votes
There 'N' different types of routers and 'J' different types of jobs to be performed on all these routers. Design a system wherein user could easily perform these jobs on these routers.

Ex- Say two types of routers are - DLink , Netgear. If user wants to change the IP address (a job), DLink exposes a public API to do it. NetGear needs the data in form of xml.

Was asked to design Entities involved and their communications, basic algorithm, data-storage logic if any.

- 0of 0 votes
With given Binary Tree below, traverse the tree and print the tree from bottom up order

1

/ \

2 3

/\ /\

4 5 6 7

output: 4567231

Hint: the traverse is called "Level Order Tree Traversal"

I hope someone memorize this traversal and pass the exam and all these companies judging canditates with one algorithm could think they hired the best canditate.

- 0of 2 votes
How would you design Amazon Lockers?

Amazon Lockers - Customers can use these lockers to have their products delivered. These lockers are physically available to customers at the same or several nearby zip codes.

- 0of 0 votes
The amazon site was working just fine until yesterday. But in the past 24 hours processing the customer orders is taking a really long time.

How would you debug and fix the issue?

When I asked if anything had changed in the past 24 hours, I was told several new products had been added after which the performance issues were noticed.

- 3of 3 votes
Given the root of a Binary Tree along with two integer values. Assume that both integers are present in the tree.

Find the LCA (Least Common Ancestor) of the two nodes with values of the given integers.

2 pass solution is easy. You must solve this in a single pass.

- 1of 1 vote
You are given 2 lists -

List 1: List<Demand> is a list of Demand objects.

List 2: List<Supply> is a list of Supply objects.

Return a result fulfillment List<Demand,List<Supply>>.

This means each demand could be satisfied by more than one supplies.`class Demand { Date startDate; Date expirationDate; int quantity; } class Supply { Date startDate; Date expirationDate; int quantity; }`

The Demand and Supply refers to that of groceries. You must map supplies to a demand only if the supply still has at least 3 days remaining to its expiration before the demand can be fulfilled.

A demand is said to be fulfilled 24 hours after all demands have been mapped to correspondingly available supplies.

- 2of 2 votes
Given a string with only parenthesis. Check if the string is balanced.

ex -

1) "<({()})[]> is balanced

2) "<({([)})[]> is not balanced

- 0of 0 votes
Write code for the partition subroutine in Quicksort.

- 1of 1 vote
How would you Design a HashTable?

In what ways would you attempt to address collisions?

- 2of 2 votes
find first not-repeating character by iterating through the length of the string only once and by using constant space.

- 1of 1 vote
We define an undirected graph g,such that: The total number of nodes in the graph is g_nodes. The nodes are numbered sequentially as 1,2,3….g_nodes. The total number og edges in the graph is g_edges. Each edge connect two distinct nodes(i.e no edge connect a node to itself). The weight of the edge connecting nodes g_to[i] and g_from[i] is g_weight[i]. We define the weight of the path from some start node to some end node to the sum of all edges traversed on the path. Input formate: The first line contain two space-seperated integer describing the respective value of g_node and g_edge. Each line I of the g_edge subsequent lines contain three space –seperated integer describing the respective value of g_to[i],g_from[i] and g_weight[i]. The next line contain an integer denoting start The next line contain an integer denoting end. The next line contain an integer denoting w_extra. input 1:

4 4

1 2 2

2 3 1

2 4 2

3 4 3

1

4

5

Output:4

input2:

5 5

1 2 2

1 4 4

2 3 1

3 4 3

4 5 1

1

4

2

output:3

Int mincost(int g_nodes,int g_edged,int* g_from,int* g_to,int* weight,int start,int end,int w_extra)

{

}

- 0of 2 votes
write a SQL query to retrieve the number of students that received a GPA of 3 or 4. the query should return Total number of students that receive a GPA of 3 separate from Total number of students that receive GPA 4.

Schema:-

Student:- Student_ID, name, phoneno, email, gpa, gradyear

Classes: Class_ID, name, description

student_classes:- Class_ID, Student_ID, Grade

- 1of 1 vote
Design a service to generate unique 64 bit IDs

- 0of 0 votes
Given a set of numbers, find out all subsets of the set such that

the sum of all the numbers in the subset is equal to a target number.`s = [ 1, 2, 3, 4, 5 ] target = 5 op = [ [ 1,4 ] , [2,3] , [5] ]`

Application: Given a fixed budget, and work items we are doing back filling to check what all we can attain with the budget.

Continuation. Imagine the set is actually a set of work items, with cost and utility involved :`def work_item : { name : 'foo bar' , cost : 10 , utility : 14 }`

Now, solve this to maximise utility.

Continuation. Imagine that the work items are related, so that, if work item w1 is already in the

subset of the work items selected, w2 's utility increases further!.

( Can you imagine how it can happen? Effectiveness of Mesi increases when he plays for Barca)

So, you are given a list like this :`w1 -> normal utility 14, with w2 20, ....`

Now maximize payoff.

NOTE: Payoff is a matrix. This comes from game theory.

Hence, a payoff matrix looks like :`w1 w2 w3 w4 .... w1 w1 w2 w2 w3 w3 w4 w4`

A cell ( i,j) is filled up with if a list contains both wi and wj, then how much the payoff would be. It is a symmetric matrix.

- 2of 2 votes
Given that an external service gives a list of credit cards that have become fraud, design a fraud management system for a shopping website for bookings with fraud credit cards

- 0of 2 votes
Given a list of shops each of which have a list of toys with their prices and max number of children who can play with it at a time. Output the a list of best possible toy option from each shop given the number of children who are shopping.

ToyShopping

{

getListOfBestToysFromEachShop(List<Shop> shops);

}

Shop

{

int id,

List<Toy> listOfToys;

}

Toy

{

int toyId;

int shopId;

int price;

int maxChildren; //max number of children who can play with this toy

}

- 0of 0 votes
Function to print shortestpathsum between start and end node of given weighted undirected graph

Comlite the function:

ShortestPathSum(graph g,start,end)

Node(1)----wieght--->node(2)

Node(2)--weight-->node(3)

Node(2)----W----node(4)

Node(3)-----w----->node(5)

Node(4)---w--->node(5)

suppose node(1) is stat node and node(5) is end node

Please write the complite function

- 0of 0 votes
CAREERCUP is a boad game hat contains m x n on a board. The objective of the CAREERCUP game is to reach the bottom of he board (bottom right corner) from the top of the board (top left corner) while moving one grid at a ime in either the down, right or diagonally downwrd directions.

Write a method called CareerSolution that takes in two integers representing m and n, and returns the total number of ways a player can complete the game.

PS: Was later asked to optimize the solution.

int CareerSolution(int m, int n) {

}

- 0of 0 votes
Function to print shortestpathsum between start and end node of given weighted undirected graph

Comlite the function:

ShortestPathSum(graph g,start,end)

- 1of 1 vote
Program to print string value if each vowel of associated with value 1 and each consonant associated with value 2 print the sum of string value

Ex if input:a

Print O/p:1

I/p:ab

O/p:1+2=3

I/p:abcd

O/l:1+2+2+2=7

I/p:abcde

O/p1+2+2+2+1=8