Amazon Interview Questions
- 0of 0 votes
Answersx={a,b,c}, y={p,q}, z={r,s}
- ajay.raj March 10, 2018 in United States
Define a
Operation, x * y * z = {{a,p,r},{a,p,s},{a,q,r},{a,q,s}......{c,q s}}
Is to output all the results in the order of each subset, implementing a class iterator that has Next() and hasNext() methods| Report Duplicate | Flag | PURGE
Amazon Backend Developer - 0of 0 votes
AnswersGive a tree-like graph that lets you find the maximum length from the leaf node to the leaf node. The input is an array of edges.
- ajay.raj March 10, 2018 in United States| Report Duplicate | Flag | PURGE
Amazon Backend Developer - 0of 0 votes
AnswersLast Man Standing
- pragramticProgrammer March 09, 2018 in United States
A king gathers all the men in the kingdom who are to be put to death for their crimes, but because of his mercy, he will pardon one. He gathers the men into a circle and gives the sword to one man. The man kills the man to his left, and gives the sword to the man to the dead man's left. The last man alive is pardoned.
With 5 men, the 3rd is the last man alive.
Write a program that accepts a single parameter: a number N that represents the number of criminals to start with. The program should output the number of the last two men alive.
Example #1: myProgram 5
would output:
5, 3
Example #2: myProgram 7
would output:
3, 7| Report Duplicate | Flag | PURGE
Amazon SDE-2 - -1of 1 vote
AnswersTo determine whether two people have kinship, all data structures need their own definition
- ajay.raj March 08, 2018 in United States| Report Duplicate | Flag | PURGE
Amazon Backend Developer - 0of 0 votes
AnswerGiven an integer n (say somewhere between 100 and 1000), you want to generate a random binary tree having exactly n nodes. You are only interested in the structure of the tree. Each structurally unique tree should ideally have the same chance of being generated.
- ajay.raj March 07, 2018 in United States| Report Duplicate | Flag | PURGE
Amazon Backend Developer - 1of 1 vote
AnswersGiven a binary matrix, find if there is a path from the upper left corner to the lower right corner, meet the conditions each time the value of the cell must be different.
- ajay.raj March 06, 2018 in United States
Follow up if there is a path with the same number of 0 and 1?| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersGiven k numbers as strings. The numbers may be very large (may not fit in long long int), the task is to find sum of these k numbers.
- ajay.raj March 06, 2018 in United States
Example
S1 = “100”
S2 = “10”
S3 = “1”
Return “111”
public string addNumbers(String[] nums){
}| Report Duplicate | Flag | PURGE
Amazon Backend Developer - 0of 0 votes
AnswersThere is a process sequence that contains the start and end of each process. There is a query sequence asking how many processes are running at a certain point in time. Please return the query result of the query sequence.
- ajay.raj March 05, 2018 in United States
Example
Given logs = [[1, 1234], [2, 1234]], queries = [2], return [2].
Explanation:
There are 2 processes running at time 2.
Given logs = [[1, 1234], [2, 1234]], queries = [1, 1235], return [1, 0].
Explanation:
There is a process running at time 1, and 0 processes running at time 1235.| Report Duplicate | Flag | PURGE
Amazon Java Developer - -1of 1 vote
AnswerGiven:
- ajay.raj March 05, 2018 in United States
R number of Red Cards
B number of Black cards
K
Cards needs to be placed in a circle. Start from a position and for
every K moves remove that card And
repeat the process until all the cards are eliminated.
Question: Position the cards such that the red cards are completely
eliminated before the blacks cards are selected for elimination.| Report Duplicate | Flag | PURGE
Amazon Java Developer - 0of 0 votes
AnswersGiven a BST convert it into new Data Structure that satisfies following conditions:
1. every leaf node's left ptr point to its parent and right ptr points to the next leaf
2. every non leaf node's left ptr points to its parent and right ptr is NULL
3. return the head and print the new DSexample: 7 / \ 5 9 / \ \ 4 6 10 output: head->4->5->7 | ->6->5->7 | ->10->9-7
with optimal time and space complexity
- ajay.raj March 05, 2018 in United States| Report Duplicate | Flag | PURGE
Amazon Java Developer - 0of 0 votes
Answersinput: "kitten%20pic.jpg"
- ajay.raj March 05, 2018 in United States
output: "kitten pic.jpg"
%20 -> ' '
%3A -> '?'
%3D -> ':'
modify your input in place.
no string library functions.
void Decode(char[] str)| Report Duplicate | Flag | PURGE
Amazon Java Developer - 0of 0 votes
AnswersGiven a string T of length n, partition it in n' "phrases" (p1, p2, ..., pn'),
- ajay.raj March 05, 2018 in United States
such that
pi = pj + c, for some j<i, where + is string concatenation and c is a character
p0 = ''
p1 = pj + c where j < 1
T = p1 + p2 + ... + pn'
For example:
T = aababcabcd = a + ab + abc + abcd
p1 p2 p3 p4| Report Duplicate | Flag | PURGE
Amazon Java Developer - 0of 0 votes
AnswersPrint a binary tree in vertical order using singly linked list...
- ajay.raj March 05, 2018 in United States| Report Duplicate | Flag | PURGE
Amazon Java Developer - 0of 0 votes
AnswerThere are three threads and we want them to run
- ajay.raj March 05, 2018 in United States
one after the other. How can we do that?| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersIn a grid, you are given a position, and every location has some value.
- ajay.raj March 05, 2018 in United States
find the shortest length so that you can touch to any boundary of the grid.| Report Duplicate | Flag | PURGE
Amazon SDE1 - 1of 1 vote
AnswersYou are given a graph and an algorithm that can find the shortest
- ajay.raj March 05, 2018 in United States
path between any two nodes
Now you have to find the second shortest path between same two nodes.| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswerFind product of distinct prime
- ajay.raj March 05, 2018 in United States
factor of all numbers .
Ex
10
12
7
prime factor of 10 = 2*5
prime factor of 12 = 2*2*3
prime factor of 7 = 7
SO distinct prime factor is 2*5*3*7 = 210| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
Answersencode binary in bytes is to give a matrix of size M * N,
- ajay.raj March 05, 2018 in United States
This matrix is encoded in bytes as a 4 * 4 bool matrix
[0 0 0 0
1 0 0 1
0 0 0 0
0 0 0 1]
Will be encoded as a byte array [9, 1].
Then write a function set_one (vector <byte> arr, int M, int N, int start_row, int start_col, int end_row, int end_col);
Set all of 0 from (start_row, start_col) to (end_row, end_col) to 1
for example
start_row = 1
start_col = 2
end_row = 2
end_col = 0,
Just that 4 * 4matrix will become
[0 0 0 0
1 0 1 1
1 0 0 0
0 0 0 1]
The byte array after encode should be rewritten as [11, 129].| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
Answersfind out all of the state machine will guaranteed to come to safe state
- ajay.raj March 05, 2018 in United States
ex
A -> [B, C, D, E]
B -> [A]
C -> [D, E]
D -> [E].
E -> [safe state]
Output [C, D, E] because once these states will eventually go to safe state| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersAisles contain products. Product is only going to be in one Aisle.
- plasmalightwave March 04, 2018 in United States
Product{
AisleID: string
ProductID: string
Price: float
}
Given Array<Product>, find the N highest price combinations. Combination is 1 product from each aisle. You can choose only one instance of each product.
So if you had two aisles
1: {$5,$4,$2}
and
2: {$6,$1)
And they asked for the 2 highest combos you would give $6,$5 and $6,$4| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
AnswersWrite a simple RegEx parser function that handles only the
- ajay.raj March 04, 2018 in United States
operators * (0 or more) and + (1 or more), and returns true if
the provided string is a match. Signature:
boolean isMatch(String regex, String input).
Example: regex = a*b+ce, input = bce, return true
Example: regex = a*b+ce, input = ace, return false
Example: regex = a*b+ce, input = abcee, return false| Report Duplicate | Flag | PURGE
Amazon Software Engineer - 0of 0 votes
AnswersGiven a tree and a number N,
- ajay.raj March 04, 2018 in United States
construct another tree such that each node of the tree has either 0 or
N elements,except for one node which has between 0 to N elements.
Only other constraint is
that ancestry is preserved in the new tree.| Report Duplicate | Flag | PURGE
Amazon Software Engineer - 0of 0 votes
Answersgiven start and end of a given set of meetings, asking how to schedule
- ajay.raj March 04, 2018 in United States
as many meetings as possible。| Report Duplicate | Flag | PURGE
Amazon Software Engineer - 0of 0 votes
Answersfind a points that has same distance to given three points
- ajay.raj March 04, 2018 in United States| Report Duplicate | Flag | PURGE
Amazon Java Developer - 0of 0 votes
Answersinput is an int [] number is the car number parked in the parking lot, 0 for empty spaces
- ajay.raj March 04, 2018 in United States
Output is also an int [] requires a method to convert the input into target array.
Each car can only be exchanged with a 0.| Report Duplicate | Flag | PURGE
Amazon Java Developer - 0of 0 votes
Answers
- ajay.raj March 04, 2018 in United StatesGiven a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representation of s1 = "great": great / \ gr eat / \ / \ g r e at / \ a t To scramble the string, we may choose any non-leaf node and swap its two children. For example, if we choose the node "gr" and swap its two children, it produces a scrambled string "rgeat". rgeat / \ rg eat / \ / \ r g e at / \ a t We say that "rgeat" is a scrambled string of "great". Similarly, if we continue to swap the children of nodes "eat" and "at", it produces a scrambled string "rgtae". rgtae / \ rg tae / \ / \ r g ta e / \ t a We say that "rgtae" is a scrambled string of "great". give a string s, print all the scrambled string of it class Solution { public List<String> ScrambleString(String s) { } }
| Report Duplicate | Flag | PURGE
Amazon Java Developer - 0of 0 votes
AnswersThe problem is to count all the possible paths from any points to bottom right of a mXn matrix with the constraints that from each cell you can either move only to right or down
- ajay.raj March 03, 2018 in United States| Report Duplicate | Flag | PURGE
Amazon Backend Developer - 0of 0 votes
AnswerFind the final states of a n-nary tree
- ajay.raj March 02, 2018 in United States
each node has three states, 0,1,2.
Require that if all child nodes are 2,
The parent node is also 2.
All child nodes are 0, the parent node is 0, and the rest are all 1s.| Report Duplicate | Flag | PURGE
Amazon Backend Developer - 0of 0 votes
AnswersGiven two functions, start (id, start_time), stop (id, time),
- ajay.raj March 02, 2018 in United States
Respectively, to the id assignment start and end time, gave a bunch of such operations (to ensure that the operation start small id first appeared,
And each id last have start_time and stop_time), press the start order to print the corresponding id, start_time, stop_time,
Requirements of space complexity as small as possible,
e.g., start (1, 1), start (2, 2), stop (2, 3), start (3, 4), stop
The print order is (1,1,6), (2,3,2), (3,4,5) # (id, start_time, end_time).| Report Duplicate | Flag | PURGE
Amazon Backend Developer - 0of 0 votes
AnswerTo several bus lines, each line is a two-way line, such as:
- ajay.raj March 01, 2018 in United States
0: A <-> B <-> D
1: C <-> D
After writing the map, give you a start and end, let me find the path through the least station.| Report Duplicate | Flag | PURGE
Amazon Backend Developer