## Amazon Interview Questions

- 0of 0 votes
Given 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.

Example

S1 = “100”

S2 = “10”

S3 = “1”

Return “111”

public string addNumbers(String[] nums){

}

- 0of 0 votes
There 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.

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.

- -1of 1 vote
Given:

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.

- 0of 0 votes
Given 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 DS`example: 7 / \ 5 9 / \ \ 4 6 10 output: head->4->5->7 | ->6->5->7 | ->10->9-7`

with optimal time and space complexity

- 0of 0 votes
input: "kitten%20pic.jpg"

output: "kitten pic.jpg"

%20 -> ' '

%3A -> '?'

%3D -> ':'

modify your input in place.

no string library functions.

void Decode(char[] str)

- 0of 0 votes
Given a string T of length n, partition it in n' "phrases" (p1, p2, ..., pn'),

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

- 0of 0 votes
Print a binary tree in vertical order using singly linked list...

- 0of 0 votes
There are three threads and we want them to run

one after the other. How can we do that?

- 0of 0 votes
In a grid, you are given a position, and every location has some value.

find the shortest length so that you can touch to any boundary of the grid.

- 0of 0 votes
You are given a graph and an algorithm that can find the shortest

path between any two nodes

Now you have to find the second shortest path between same two nodes.

- 0of 0 votes
Find product of distinct prime

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

- 0of 0 votes
encode binary in bytes is to give a matrix of size M * N,

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].

- 0of 0 votes
find out all of the state machine will guaranteed to come to safe state

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

- 0of 0 votes
Aisles contain products. Product is only going to be in one Aisle.

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

- 0of 0 votes
Write a simple RegEx parser function that handles only the

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

- 0of 0 votes
Given a tree and a number N,

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.

- 0of 0 votes
given start and end of a given set of meetings, asking how to schedule

as many meetings as possible。

- 0of 0 votes
find a points that has same distance to given three points

- 0of 0 votes
input is an int [] number is the car number parked in the parking lot, 0 for empty spaces

Output is also an int [] requires a method to convert the input into target array.

Each car can only be exchanged with a 0.

- 0of 0 votes
`Given 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) { } }`

- 0of 0 votes
The 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

- -1of 1 vote
We have two sequences A and B consisting of integers, both of length N, and you would like them to be (strictly) increasing, i.e. for each K (0 ≤ K < N − 1), A[K] < A[K + 1] and B[K] < B[K + 1]. Thus, you need to modify the sequences, but the only manipulation you can perform is to swap an arbitrary element in sequence A with the corresponding element in sequence B. That is, both elements to be exchanged must occupy the same index position within each sequence.

For example, given A = [5, 3, 7, 7, 10] and B = [1, 6, 6, 9, 9], you can swap elements at positions 1 and 3, obtaining A = [5, 6, 7, 9, 10], B = [1, 3, 6, 7, 9].

Your goal is make both sequences increasing, using the smallest number of swaps.

Write a function:

public int minswaps(int[] A, int[] B);

that, given two zero-indexed arrays A, B of length N, containing integers, returns the minimum number of swapping operations required to make the given arrays increasing. If it is impossible to achieve the goal, return −1.

For example, given:

A[0] = 5 B[0] = 1

A[1] = 3 B[1] = 6

A[2] = 7 B[2] = 6

A[3] = 7 B[3] = 9

A[4] = 10 B[4] = 9

your function should return 2, as explained above.

Given:

A[0] = 5 B[0] = 2

A[1] = -3 B[1] = 6

A[2] = 6 B[2] = -5

A[3] = 4 B[3] = 1

A[4] = 8 B[4] = 0

your function should return −1, since you cannot perform operations that would make the sequences become increasing.

Given:

A[0] = 1 B[0] = -2

A[1] = 5 B[1] = 0

A[2] = 6 B[2] = 2

your function should return 0, since the sequences are already increasing.

Assume that:

N is an integer within the range [2..100,000];

each element of arrays A, B is an integer within the range [−1,000,000,000..1,000,000,000];

A and B have equal lengths.

Complexity O(N)

- 0of 0 votes
Find the final states of a n-nary tree

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.

- 0of 0 votes
Given two functions, start (id, start_time), stop (id, time),

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).

- 0of 0 votes
To several bus lines, each line is a two-way line, such as:

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.

- 0of 0 votes
Output the second index corresponding to the first one, requiring output only if there is only one match, and false if there is more than one pair

a b c d e f g a b -> [0,1]

a b b c, a b c -> False

- 0of 0 votes
Check if characters of a given string can be swaped to form target string

ab : ba true

ac : ab false

- 0of 0 votes
`1 \ 2 - 3 \ / 4 | 5 - 8 | / 7 For the undirected graph, the LCS is 2,3,4,5, so how can we find it? For a undirected graph, find the Longest Consecutive Sequence`

/**

* Definition for undirected graph.

* class UndirectedGraphNode {

* int label;

* List<UndirectedGraphNode> neighbors;

* UndirectedGraphNode(int x) { label = x; neighbors = new ArrayList<UndirectedGraphNode>(); }

* };

*/

public class Solution {

public List<Integer> longestGraph(List<UndirectedGraphNode> nodes) {

}

}

- 0of 0 votes
/*Coding question: The customers for a particular business, required to use a webpage to select a Browse Node.

A Browse Node, is an element in the classification structure used to classify products in the Amazon webpage.

The products are classified in 8 categories. Each category has its own sub-classification that looks like a tree with many

children per node and many levels. The UI developer has a tool to paint such tree. He requires from you (You are the backend developer)

to implement 2 interfaces for him:

Node getRoot();

List<Node> getChildren(Node node);

The data is available for you in a text file with this format:

//nodeid, parent_node_id, nodename

Example:

//nodeid, parent_node_id, nodename

10, 1, Comedy Books

20, 2, Tablets

1, -1, Books

11, 1, Novels

12, 11, Terror novels

2, -1, Electronics

-1, 0, GlobalRoot

*/

- -1of 1 vote
Remove '_' and print with 1 space separated string from "Amazon_w_e_b_services are___widely__used_acc__ro___ss_the_worl_d", output should be : Amazon web services are widely used accross the world.