Amazon Interview Questions
- 0of 0 votes
AnswersTo an array and K, each element in the array can only move K positions to the left at most, no limit to the right, try to sort the array under the limit of K
- ajay.raj April 10, 2018 in United States
a = [5, 2, 4, 3, 1], k = 2
Return [2, 3, 1, 4, 5]| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersGiven a function rand32() (random number range 0-2**32-1) that randomly generates a 32-bit int, design a new random function:
- ajay.raj April 09, 2018 in United States
Randn(n) generates a random distributed random number (0 - 2**n-1)
Rand3n(n) generates (0 - 3**n-1) the uniformly distributed random number| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswerTopic: There is a set of coordinates. The original format of each coordinate is (1.3, 0.5). However, the comma and decimal point are gone. Only one string is left, allowing you to restore all possible combinations. For example, 123, possible (1, 23) (1, 2.3) (12, 3) (1.2, 3)
- ajay.raj April 09, 2018 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
Answersgiven period and threshold, Assume there is a endless streaming events, each event occurs at timestamp "x". The question want you to write an API that return true if number of the events are over the threshold within the period around timestamp "x"
- ajay.raj April 08, 2018 in United States
Ex:
period = 3, threshold =2
getEvent(10) -> false
getEvent(12) -> false
getEvent(13) -> true [10,12,13]
getEvent(20) -> false
part one: event come in order
part two: event come without order| Report Duplicate | Flag | PURGE
Amazon Software Developer - 0of 0 votes
AnswersGiven vector<int> nums, and pair<int, int> range. Find out how many continuous subsequences within this vector sum up the number within the range.
- ajay.raj April 08, 2018 in United States
Input: [1, 2, 3], [3,6]
Output: (4)
because [1,2,3], [1,2], [2,3], [3]| Report Duplicate | Flag | PURGE
Amazon Software Developer - 0of 0 votes
AnswerEach have a (x,y) coordinate.
- ajay.raj April 08, 2018 in United States
Write an API that group three Googler together for lunch if they are close enough. Otherwise, throw them in un-schedule pool.
Distance formula = sqrt((x1-x2) ^2 + (y1-y2) ^2)
Given an int range;
Range: 2
Input | Output of API Un-schedule pool
0,0 -> [] [[0,0]]
1,0 -> [] [[0,0], [1,0]]
3,0 -> [] [[0,0], [1,0], [3,0]]
1,1-> [[0,0], [1,0], [1,1]] [[3,0]]| Report Duplicate | Flag | PURGE
Amazon Software Developer - 0of 0 votes
AnswersGiven an vector<int> nums and an int target, you can change any element of the vector to positive or negative. How many uniquely different vector sum up to target?
- ajay.raj April 08, 2018 in United States
Input: [1,1,1], target = 2
[-1,1,1]
[1,-1,1]
[1,1,-1]
return (3)| Report Duplicate | Flag | PURGE
Amazon Software Developer - 0of 0 votes
Answerfind max path sum in DAG, weight can be negative
- ajay.raj April 06, 2018 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer - 0of 0 votes
AnswersImplement a method to check if a n-ary tree is unival
- ajay.raj April 04, 2018 in United States
class TreeNode {
int val;
List<TreeNode> children;
TreeNode(int val) {
this.val = val;
children = new ArrayList<>();
}
}| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersGiven the length and width of a rectangle, how many ways can be used to go from the upper left corner to the upper right corner (each step can only go to the right, top right or bottom right):
- ajay.raj April 03, 2018 in United States
-follow up 1: If three points in the rectangle must be visited, how many ways
-follow up 2: If you are given an point H, and the path must go down below the H point, how to do it| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersThe thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. After a tour, the smart thief realized that "all houses in this place forms an n-nary tree". It will automatically contact the police if two directly-linked houses were broken into on the same night.
- ajay.raj March 31, 2018 in United States
Determine the maximum amount of money the thief can rob tonight without alerting the police.
/**
* Definition for a n-ary tree node.
* public class TreeNode {
* int val;
* List<TreeNode> kids;
* }
*/
class Solution {
public int rob(TreeNode root) {
}
}| Report Duplicate | Flag | PURGE
Amazon SDE1 - 1of 1 vote
AnswerFor two string a, b, their distance is defined as the number of positions at which the corresponding character are different.
- ajay.raj March 31, 2018 in United States
Now you can swap characters at any two locations once, and ask how to swap to make the distance the smallest.| Report Duplicate | Flag | PURGE
Amazon Backend Developer - 0of 0 votes
Answerspreorder Traversing a n-ary tree without using recurrsion
- ajay.raj March 31, 2018 in United States
TreeNode<T> {
T val;
List<TreeNode> children;
}| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersGiven two methods for the person class, one to find a dad and one to find a mother, using these two methods to achieve a method to determine whether the two people are related to blood, assuming a limited number of people.
- ajay.raj March 30, 2018 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersSelf-implemented data structures and methods, output all the heirs. To achieve birth (parent, name), dead (name), getAllSucession (). There is a king, you can use birth plus children, dead dead. The order of inheritance is the same as preorder except that this tree has multiple children.
- ajay.raj March 30, 2018 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersGiven an Input file of IPv4 addresses, filter and write them into Valid and Invalid IPs.
- pragramticProgrammer March 28, 2018 in United States
Input file = ["192.100.0.1, "10.0.0.1", "aa.bb.cc.dd", "10.0", "999.10.10.1"]
Valid = []
Invalid = []| Report Duplicate | Flag | PURGE
Amazon Software Engineer - 0of 0 votes
AnswerA coffee machine has three buttons (S, M, L). After pressing each button, the coffee machine will flow out of a range of coffee [s1, s2], [m1, m2], [l1, l2], but the outflow of coffee The amount is random. There is a cup with a total capacity of c2. There is a tick c1 on the cup. If the amount of coffee is [c1, c2], it is considered full.
- ajay.raj March 28, 2018 in United States
After asking for a series of button operations, can the coffee be filled in [c1, c2] but not overflow?| Report Duplicate | Flag | PURGE
Amazon Backend Developer - 0of 0 votes
AnswersInput like method stack trace: "main, start", "foo, start", foo, end", "bar, start", "bar end", "main, end", "main2, start", "main2, end"
Output String, such as the following format, to indicate the order in which the method was called and the hierarchy
- ajay.raj March 28, 2018 in United Statesmain Foo Bar main2
| Report Duplicate | Flag | PURGE
Amazon Backend Developer - 0of 0 votes
Answerspublic TreeNode{
int val = val;
TreeNode left, right;
public TreeNode(int val){
this.val = val;
}
given a tree and an API, delete a part of the nodes in the tree and return the forest formed after the node is deleted.
public List<TreeNode> deletenodes(TreeNode root, List<TreeNode> toDeletes){
}
example
- ajay.raj March 28, 2018 in United States1 / \ 2 3 / / \ 4 5 6 If you delete the 2 and 5 nodes, you will need to return to the forest [4, 1] \ 3 \ 6
| Report Duplicate | Flag | PURGE
Amazon Java Developer - 0of 0 votes
Answersturns the following format string into a tree: node has keys, values, and subtrees.
- ajay.raj March 23, 2018 in United States
For example, the first key is node1 and the value is ‘aaaa’
<node1>aaaaa<node2>bbbbb</node2><node3>cccc</node3><node4>dddd</node4></node1>| Report Duplicate | Flag | PURGE
Amazon Backend Developer - 0of 0 votes
Answersfind longest common suffix of two linked list.
- ajay.raj March 18, 2018 in United States| Report Duplicate | Flag | PURGE
Amazon Backend Developer - 0of 0 votes
AnswersGive a 0/1 matrix to find and remove the islands. Assume that the boundaries of the matrix are 1
- ajay.raj March 15, 2018 in United States
The definition of islands is surrounded by 0
The simplest example is
enter:
111111
100001
100101
100001
111111
Output:
111111
100001
100001
100001
111111| Report Duplicate | Flag | PURGE
Amazon Backend Developer - 0of 0 votes
AnswersWrite a hash function so that a string and its reverse get the same return value
- ajay.raj March 15, 2018 in United States
Hash(‘banana’) == hash(‘ananab’)
Hash(‘banana’) == hash(‘banana’)
Hash(‘banana’) != hash(‘banaaa’)| Report Duplicate | Flag | PURGE
Amazon Backend Developer - 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
Open Chat in New Window