## Amazon Interview Questions

- 0of 0 votes
Given a matrix. Convert it into a linked list matrix such that each node is connected to its next right and down node.

Ex:

1 2 3

4 5 6

7 8 9

Output:

1->2->3->NULL

| | |

v v v

4->5->6->NULL

| | |

v v v

7->8->9->NULL

| | |

v v v

--NULL-

This is my code.`class Ideone { public static void main(String args[]) throws Exception { int arr[][] = { { 1, 2, 3 }, { 4, 5, 6 } }; LList op = convert2DArrintoList(arr, 0, 0); System.out.println(op); } public static LList convert2DArrintoList(int arr[][], int col, int row) { if (col >= arr[0].length || row >= arr.length) return null; return new LList(arr[row][col], convert2DArrintoList(arr, col, row + 1), convert2DArrintoList(arr, col + 1, row)); } static class LList { LList(int data) { this.data = data; } LList(int data, LList down, LList next) { this.data = data; this.down = down; this.next = next; } LList() { this.data = Integer.MAX_VALUE; } @Override public String toString() { return " " + this.data + " "; } int data; LList next; LList prev; LList rand; LList down; } }`

Are there better ways of doing it?

- 0of 0 votes
// Create a numeric binary tree structure/classes that have left and right children and an integer numeric value.

// Write a function 'isBalanced' for a node that returns true if the sum of all the children on the left is equal

// to the sum of all the children on the right.

//Example:

// [12] [12].isBalanced() -> True. [3, 3]

// / \

// [3] [1] [1].isBalanced() -> True. [2, 2]

// / \

// [2] [0]

// / \

// [2] [0]

// - Part I: setup and isBalanced() function

// - Part II: implement “allBalancedNodes()” <— given a node, finds all balanced children

// allBalancedNodes(12) -> returns a list of balanced nodes: { [1], ... }

- 0of 0 votes
Given a fully connected graph with n nodes and corresponding values. One node can interact with other node at a time, to replace/ignore/add its value to other node’s value. Assuming this operation takes 1 unit of time, how much time would it take for all the nodes to have value equal to sum of all the nodes.

Examples : Given a graph with values {1,2,3,4}, find total time it takes, such that all nodes have value as 10.

I am assuming it can be done in O(N).It will take basically two traversals, one for calculating the sum of values of nodes(first traversal), other for replacing the value of the nodes(second traversal).

It will take 2*(no of nodes) time.

Are there any better ways possible ?

- 0of 0 votes
Your organization is opening a new warehouse and your manager has tasked you with figuring out how to quickly get some of the inventory in the original warehouse to the new warehouse. You are given a list of the locations of all N packing crates in the facility, any of which is a candidate to be moved to the new facility. All crates are the same size, and the truck has capacity to move exactly M of them. The delivery driver needs to leave promptly, so it is your job to find the crates that are closest to the truck. Crates are heavy, so you can only carry one at a time.

Given an array of the locations of N packing crates, implement an algorithm to find the locations of the M crates closest to the truck.

Input

The input to the function/method consists of three arguments:

totalCrates, an integer representing the total number of packing crates in the facility (N)allLocations, a list where each element consists of a pair of integers representing the x and y coordinates of the packing crates;

truckCapacity, an integer representing the number of packing crates that will be moved to the new facility (M).

Output

Return a list of integers where each element of the list represents the x and y coordinates of the packing crates that will be moved to the new facility.

Constraints

truckCapacity

totalCrates

Note You begin at the truck’s location [0, 0].The distance of the truck from a warehouse location (x, y) is the square root of x^2 + y^2.If there are ties then return any of the locations as long as you satisfy returning M points.

Example Input:totalCrates = 3allLocations = [[1, 2], [3, 4], [1, -1]]

truckCapacity= 2 Output:[[1, -1], [1, 2]]

Explanation:The distance of the truck from point [1, 2] is square root(5) = 2.236 The distance of the truck from point [3, 4] is square root(25) = 5 The distance of the truck from point [1, -1] is square root(2) = 1.414 num is 2, hence the output is [1, -1] and [1, 2].

- 0of 0 votes
Design amazon's frequently viewed product page.

- 0of 0 votes
Design a ESPN like system. Ensure scaling and availability. Also one should get all details like score of a player, no. of mtches etc.

- 1of 1 vote
Write an algorithm to determine the minimum distance required to level the entire field from the shortest tree to the tallest tree

You are in charge of organizing a golf event and recently rented out a rectangular field for the event. While the field is close to what it needs to be, it needs some landscaping. The field is flat, except for trees and trenches, and can be represented as a two-dimensional grid. The flat areas are represented as 1, areas with trenches are represented by 0, and areas with trees are represented by numbers greater than 1 indicating their heights (heights are unique). Your goal is to cut down all of the trees to level the field, but you can only cut the shortest tree on the field, at any given time. You can start from any corner of the field, as long as it is flat, and can move one block up, down, left, or right at a time. You cannot walk on trenches, cannot go through a trees, and cannot leave the field. Additionally, once a tree is cut, that area is flat and you move to that area.

Input:

(numRows = an Integer representing number of rows)

(numColumns = an Integer representing number of columns)

(field = representing 2D grid of integers)

Example-1:

Input: numRows=2, numColumns=4,

Field = [1,1,1,1];

Output: 5

Explanation:

- You start from bottom right corner

- To cut the tree of height 2, the path followed is: {{1,3}, (0,3)}

- Then to cut the tree of height 3, the path continue is: {{0,3},{1,3},{1,1},{0,1}}

- So the output is 5 as the minimum time required to level the field.

Testcase-1:

Input: 2,4

Field = [[1,1,0,1], [1,1,5,1]];

Expected Output: 1

Testcase-2:

Input: 6,6

Field =

[

[1,1,0,12,1,1],

[1,1,1,1,1, 1],

[0,1,0,0,0, 1],

[0,1,1,1,14,1],

[0,0,0,0,1, 1],

[15,1,1,1,1,1]

]

Expected Output: 14

- -4of 4 votes
..

- 2of 2 votes
Design a FIDS(Flight Information Display System)

1. Consider most important classes & ignore Interfaces as of now

2. FIDS is not about reservation system but the dasboard to display

3. the information will look like:

DEPARTURES

----------------------

Attributes:

STD Airline Flight Destination/Via CheckInCounter# Gate Status ETD

Values :

12:50 KingFisher 6E352 Hyderabad A-B 23 Check-In Open 13:15

ARRIVALS

-----------------------

Attributes:

STA Airline Flight# Destination/Via Gate Status ETA

Values :

12:50 KingFisher 6E352 UK/Mumbai Terminal2 Landed 13:15

- 0of 0 votes
Given a list of employees and their bosses as a CSV file , write a function that will print out a hierarchy tree of the employees.

- 0of 0 votes
Design Distributed Web Crawler.

- 2of 2 votes
Phone Interview Amazon, Seattle

I. Get the sum of all prime numbers up to N. primeSum(N).

Follow-up: If primeSum(N) is frequently called, how to optimize it.

II. OODesign Parking Lot

- 0of 0 votes
// Imagine you have an array of N messages which is consistently having new messages added to it.

// When you loop through the array, the messages are guaranteed to be ordered chronologically by timestamp.

// Write some code that loops through the array of messages and when a unique user_id has two messages within one second of each other, call a method too_fast that takes in two parameters, the first is the older message, the second is the newer message.

// In the message examples below we would expect to call the too_fast method with the first and third message, and then again with the third and fifth message.

// message example 1 = { "container_id": 123, "item_id": 456, "success": true, "timestamp": 1499351653, "user_id": 789 }

// message example 2 = { "container_id": 111, "item_id": 222, "success": false, "timestamp": 1499351654, "user_id": 333 }

// message example 3 = { "container_id": 444, "item_id": 555, "success": true, "timestamp": 1499351654, "user_id": 789 }

// message example 4 = { "container_id": 123, "item_id": 456, "success": true, "timestamp": 1499351655, "user_id": 999 }

// message example 5 = { "container_id": 123, "item_id": 456, "success": true, "timestamp": 1499351655, "user_id": 789 }

// Within the loop you can access attributes by using message.getContainerId() or message.getItemId for example, message.getTimestamp()

- 0of 0 votes
write bash code to determine if the first number in the string is greater than 1000

STR="count ------- 43952 (1 rows)"

- 0of 0 votes
I have a Amazon Phone interview for sr. business analyst They provided a collabedit link for the interview stating that we may ask Basic programming and SQL questions.

Can someone having this experience from past help me understand what kind of questions I can expect. I honestly am a BA, PM professional with not a lot of exposure to coding or SQL. Some guidance will help me prepare better. Are the questions asked in SQL basic or quite intricate? Please advise

- 0of 0 votes
The memmove() function copies n bytes from memory area src to memory area dest. The memory areas may overlap: copying takes place as though the bytes in src are first copied into a temporary array that does not overlap src or dest, and the bytes are then copied from the temporary array to dest.

- 0of 0 votes
I've got these trees of integers; they're like regular trees, but they can share nodes.

I need to know if any branch of this tree sums to 100.

7

/ \

8 6

/ \ / \

2 3 9

/ \ / \ / \

5 4 1 100

Follow up question was how would you change the code to handle negative numbers

- 0of 0 votes
I've got these trees of integers; they're like regular trees, but they can share nodes.

I need to know if any branch of this tree sums to 100.

7

/ \

8 6

/ \ / \

2 3 9

/ \ / \ / \

5 4 1 100

Follow up question was how would you change the code to handle negative numbers.

- 0of 0 votes
Find distance between any two nodes of binary tree and binary search tree.

- 0of 0 votes
There is a conference room. N people are joining the conference. You have the start time and end time of each of them visiting it. You are asked to determine the maximum number of people that can be inside the room.

Example – Four people are visiting the conference

Person A B C D

Start (hour) 1 3 2 5

End (hour) 4 5 7 10

Answer will be – 3

- 0of 0 votes
Identifying if all the elements of a set (in enterity) is present in a list of sets.

For example checking for set1 = {1,2} in {1,2,3}, {5,6} should return true as {1,2} is present in {1,2,3}. Similiary it will be true for {1,2,8,9}, {1,2,4}

But checking for {1,2} in {1,5,6}, {2,3,1} should return false as {1,5,6} does not contain all elements of {1,2} 2 is missing

- 1of 1 vote
Given string a and string b, find all the occurences of the anagrams of a in b.

- 0of 0 votes
How would you store very large numbers that can't be store in a regular Integer or BigInteger, and make calculations

- 0of 0 votes
Design an application for people to find a place near them where they can join a team to play their favorite sport. Exp. Soccer teams open to join that are scheduled to play at a certain time and place. The application would search for the available teams to join within certain area playing within some given time period,

- 0of 0 votes
[System Design] Design a mobile application to provide nearest parking lot locations and availability?

- 0of 0 votes
[System-Design] Design air traffic control system?

- 1of 1 vote
`Lazy Bartender : There are N number of possible drinks.(n1,n2..) Has C number of fixed customers. Every customer has fixed favourite set of drinks. Bartender has to create least possible number of drinks to suffice need of all the customers Example: Cust1: n3,n7,n5,n2,n9 Cust2: n5 Cust3: n2,n3 Cust4: n4 Cust5: n3,n4,n3,n5,n7,n4 Output: 3(n3,n4,n5)`

- 0of 0 votes
Given transactions between group of friends. How to minimize the number of transactions by eliminating redundant cash flow paths?

- 0of 0 votes
Write second most repeating word in a string

eg aaa bbb ccc aaa bbb aaa

answer - bbb

- 0of 0 votes
Design a suggestions list [system design] for words starting with prefix that user has typed on kindle device . The search is based on most frequent item occurring at the top to least frequent item at the bottom. Most frequent item depends on the usage of word globally.

For e.g user types "dra" . There should be a list of suggestions starting with dra such as dragon, drape, dracula etc based on their frequency of usage.