## Amazon Interview Questions

- 0of 0 votes
Today is school picture day and everybody,

including the teacher, has lined up in a single line for the class picture.

Design an O(n log n) Java code that computes the minimum number of swaps necessary to be in order

- 0of 0 votes
Given is a large paper with n different points with coordinates (x1, y1),(x2, y2), . . . ,(xn, yn).

Keep folding at 45 degres

- 2of 2 votes
Check if an integer array is arithmetic sequence.

Example: 1, 2, 3, 4, 5, 6, 7, 8 => true

1, 3, 5, 7, 9 => true

Array may not be sorted.

- 0of 0 votes
Design a chat application. How will u handle huge data?

- 0of 0 votes
Design an online pizza delivery system. Complete OO Design needed.

- 0of 0 votes
Given a 2D array of digits, try to find the occurrence of a given 2D pattern of digits. For example, consider the following 2D matrix:

7283455864

6731158619

8988242643

3839505324

9509505813

3843845384

6473530293

7053106601

0834282956

4607924137

Assume we need to look for the following 2D pattern:

950

384

353

- 2of 2 votes
find the maximum depth in a binary tree.

- -1of 1 vote
given an integer array , find all combinations which sum to a given number. If a number is used once, it must not be used again.

eg if input array is 6444 and sum =10

output must be just 6 4

Give an O(n) solution

- 0of 0 votes
given a string with only paranthesis - find out if it is balanced or not

eg {}[]()

followup : scale your solution and specify the right data structure to use if you have a lot of such bracket types

- 0of 0 votes
how can i merge 2 nodes in a graph in 1 node , need to save the in and out edges and the nodes that was merged for contribution after that

for example a graph implementation in adj list:

1->3->4->6

2->3->4->6

5->4->6

and i want to merge the nodes 3 and 4 , then new nodes should be created 7 as :

1->7->6

2->7->6

5->7->6

7->6

the node 7 also will save [include 3,4 the merged nodes]

any one can help with that please

typedef struct AdjListEntry {

int visited;

int index;

struct AdjListNode current; // node iniformation

struct AdjListEntry* next;

} AdjListEntry;

typedef struct AdjListNode {

int Uind;

char name[10];

char label[10];

adjOutEddgeLists *outEddges;

//adjInEddgeLists *inEddges;

} AdjListNode;

typedef struct adjOutEddgeLists{

AdjListNode *listNode;

adjOutEddgeLists *next;

}adjOutEddgeLists;

- 0of 0 votes
given a string, calculate the frequency of characters, output the array with the letter and frequency. (such as: for “abbcdc”, the output should be (a,1),(b,2),(c,2),(d,1))

- 0of 0 votes
You are at Amazon search-box, please specify, what Test Cases / Test Plans would you write down: Just name them, don't provide steps, consider wider scope not just functionality.

- 0of 0 votes
Hi.For the online assessment test - Debugging , which programming languages code snippet I can expect?Thank you !

- 0of 0 votes
This is was asked in Amazon SDE online test from Hacker rank.

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

- 0of 0 votes
Given a list of tuples {x, y, x' } that describe histograms on the X/Y axis, such that X is the X coordinate, Y is the Y coordinate, and X' is the distance from X, write a function that draws the skyline of these tuples.

For example:

{3, 2, 4} , {4,5,3} will give the following points:

{3,0} - trivial

{3,2} - trivial

{4,5} -calculated

{7,0} -if list is done.

You cannot assume that the tuples are sorted. Provide runtime analysis.

- 0of 0 votes
Given a list of integers of size n, write a method to write all permutations the list; do this in O(1) space

Hint: No recursion.

- 0of 0 votes
Description:

A company, create classes for each type of employee and calculate working hours and wages/salaries that will be received.

Example General Manager, IT Manager, Accounting, Marketing, Finance, Procurement Managers

Manager and Higher level employees wont have overtime wage. Overtime wage is 1.5 times higher than the usual wage. Working hours are limited as 8 hours. More than this limit will be considered as overtime.

Inputs:

Employee Name, Surname

Title/Role

Salary

Daily Working hour

Outputs:

Date

Employee Name, Surname

Daily Wage.

- 0of 0 votes
I have a photo storage service. The actual photos are present in some storage and the index of these photos is present at some other place. The index is huge, say trillions of photos. Design the class for index node of each photo (with attributes like name*, date*, size*, accesscontrol, camera details, shot details, etc) such that 1. It is serializable. 2. For faster processing, I am interested in first 3 attributes. When deserializing the bytes of object, parse these 3 attributes i.e. instead of deserializing whole class, deserialize only part of the class (members marked by*), other members of class should be deserialized on demand with another call.

How will you test the performance of your serialization/ deserialization?

- 0of 0 votes
there is a chess board of dimension n X n. You are given with 2 squares on that board S(x1,y1) ;M(x2,y2). S is a fixed point. M can move diagonally. it can move any number of steps or jumps in 1 move . Find the minimum number of moves M needs to reach S

- 1of 1 vote
there is a news publishing/subscribing product of Amazon where electronic contents are collected from owners like newspaper, magazines. Customer is using kindle. Design how customer will get the content when his system kindle connects to net. how to send the contents to device?

- 0of 0 votes
Given a number (200), compare it to four variables (E.G A,B,C,D) and return true if they are all equal to the given number.

Do this in the most efficient way, and if possible without if statements.

- 0of 0 votes
This was a design question, discuss data structures/ complexities, etc.

There is a huge HashMap (Key-Value store). This is present in storage, dont worry about the Storage.

1. Build its index. Distributed system for indexing. Different cases: Key is a String/ Double/ complex structure, etc. How will you replicate this index structure - whole index is replicated/ parts of index are replicated.

2. How will you synchronize access (read/ write) if there are multiple replicas of the index partition. What if the actual Storage partition also has replicas.

- 0of 0 votes
i need to write code that union two nodes from graph G Vi ,Vj

then new node will generated Vm = ViUVj

- 6of 6 votes
Find missing element in the A.P.

- 0of 0 votes
Implement the power function with o(logN) time complexity and O(1) space

- 1of 1 vote
create palindrome in javascript, by appending a minimum set of characters at the end.. eg. test => testset

- 0of 0 votes
Given a log file:

some garbage...from:123.54,78.21...more garbage..to:56,82,124.54...more

some more garbage...from:11.54,45.84...garbage..to:115.87,98.65

...

Write a program or shell script to return pairs of (from, to) coordinates.

Assumption: these coordinates will always appear in sequence: from ... to... from ... to...

But these from - to pair may or may not be on same line.

- 1of 1 vote
Given an array, find the first element that appears an even number of times.

- 1of 1 vote
Given a circular linked list. Find the longest sequence of numbers, where a sequence starts with any number, for example 3, and ends when you see that number again,another 3.

Imagine the circular linked list

3 8 9 7 2 1 3 4 6 [3] same as first element .i.e three.

The longest sequence would be 3 8 9 7 2 1 , the other candidate being 3 4 6

Finding for instance,starting at 8 and getting to the same 8 wouldn't count as a valid sequence.

- 1of 1 vote
Given a 8 by 8 matrix, find all possible paths , moving one cell downwards or on cell to the right,(one cell per movement ) from cell 0,0 , to cell 7,7