Leave your Email to get the latest Amazon interview questions weekly.

We'll never share your email with anyone else.

No spam we promise.

Closest Pair of Molecules

Given a list of molecules, return the distance between the closest pair...

Check Product Sequence II

Given a list of products, and a product priority sequence, return the length of the shortest product sublist that satisfies the priority sequence...

Rename Duplicate Files

Given a list of file names in a system, write a program to rename the duplicate files...

Find Cut Vertices

Given an undirected graph, find out all the vertices when removed will make the graph disconnected...

Find Bridges In A Graph

Given a graph with node from 1 to n, and a list of integer pairs represent edges, return all the bridges...

Longest Consecutive Integers

Given an integer floor and an integer ceil, and a list of holes, find the length of the longest consecutive integers...

Check Product Sequence

Given a list of products, and a product priority sequence, check if the input satisfies the priority sequence...

Cache Hit Ratio

Given a cache and a list of incoming queries, return the cache hit ratio.

Maximum Bounded Array

Build an array by values within the range from LowerBound to UpperBound...

Discount Calculator

Reduce all prices in the input text by 25%. Round to the nearest cent...

Max Sink Area

Given an M * N matrix, where matrix[i][j] is the height of the block on position (i, j). Each block has 4 neighbors - the blocks at its top, bottom, left and right. A sink area is a group of neighboring blocks that are fully surrounded by other blocks with greater heights. When water is poured onto the matrix, the sink area traps the water in it. Build a function that finds the number of blocks in the maximum sink area...

Two Sum Smaller Than Target

Find a pair of entries from two lists that yield a sum that is as close to a target number as possible, without exceeding it...

Product Search

Design the simple search function for products on Amazon...

Rearrange String

Given a string str and an integer k, you need to rearrange the string in a way that the same characters must be at least k distance away. If not possible, return "".

Example:

Input:

str = "aabb", k = 2

Output:

You can return either "abab" or "baba".

Cut Binary Search Tree

Given a BST, and an integer k, cut the BST vertically into two substrees A and B, where all nodes in A <= k and all nodes in B > k.

Contrain: for any node A and it’s parent B in the original BST. If after the cut they are both in the same subtree. B should still be the parent of A.

Least Common Ancestor Of Multiple Nodes

Given a binary tree and a list of nodes say [n1, n2, .. nk], write a program to find the least common ancestor.

...

Remove Duplicated IPv4 Addresses
#### [Amazon Onsite Question] Remove Duplicated IPv4 Addresses

You are given a huge number of IPs in a list. Remove all duplicated addresses from the list.

2Sum NAry Trees

Two people from different teams will work together on a project that requires a total of T hours. Each team is represented as an N-ary tree where a tree node is a team member and the number of hour(s) the member can devote to the project. Find out all the unique combinations of hours that both people's work [t1, t2] add up to T hours...

Linux Find Command

Input: a list of filenames with paths You need to complete the following class to support linux find command.

Play Movies

You are on a flight and want to watch two movies during this flight. You need to pick two movies and the total duration of the two movies is less than or equal to d.

Find Unreachable Servers

Find out all broken connections in the data center...

Minimum Total Container Size

Given k days and array P as the item sizes, find out the minimum total container size required to move all the items...

Design ID Generator

Design an class to generate unique ID for new users.

Zombie Matrix

Given a 2D grid, each cell is either a zombie or a human. Zombies can turn adjacent (up/down/left/right) human beings into zombies every day. Find out how many days does it take to infect all humans?

Buy Ice Cream

A queue of people are waiting to buy ice cream from you.

Each person buys one ice cream, which sells for $5.

Each customer is holding a bill of $5, $10 or $20.

Your initial balance is 0.

Find whether you will be able to make change for every customer in the queue. You must serve customers in the order they come in.

Count Number in Sorted Array

Given a sorted array of integers and a target number, return the count of the target number...

First Unique Number in an Infinite Stream

Implement the following class to keep track of the first unique number in a data stream...

LRU Cache II
##### LRU Cache With TTL

Design and implement the Least Recently Used Cache with TTL(Time To Live)

**Expalnation** on the eviction stragedy since people have questions on the testcase:

1, after the record expires, it still remains in the cache.

2, when the cache reaches the capacity, it first evicts the expried records. If there are more than one expired records, evict the one with the minimum expire timestamp.

...

Word Search Longest

You can find a word in 2d array if the word is constructed by a sequence of adjacent letters

Check Valid Equations

Given a series of equations e.g. [A = B, B = D, C = D, F = G, E = H, H = C]
and then another series [A != C, D != H, ..., F != A ]

Check whether the equations combined is valid.

For the example given, your program should return 'invalid', because the first series implies that A = C, which contradicts the statement A != C in the second series.

Check Preorder

Given an ArrayList of Nodes, with each Node having an ID and a parent ID, determine whether the List is given in preorder.

Prime Sum

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

Find The Left View Of Binary Tree

AWS phone interview

Find the left view of binary tree

```
1
/ \
2 3
/\ \
4 5 6
/ /
7 8
/
9
```

return [1, 2, 4, 7, 9]
Find All Anagrams

Find the indices of all anagrams of a given word in a another word.

For example: Find the indices of all the anagrams of AB in ABCDBACDAB

(Answer: 0, 4, 8)

Cut Binary Tree

Give a binary tree, find if it's possible to cut the tree into two halves of equal sum. You can only cut one edge.

Unique Letter String

For example, UNIQ("LETTER") = 2.

Given a string S with only uppercases, calculate the sum of UNIQ(substring) over all non-empty substrings of S.

If there are two or more equal substrings at different positions in S, we consider them different. Since the answer can be very large, retrun the answer modulo 10 ^ 9 7.
Closest Leaf Node

Given a binary tree, find the closest LEAF node to the target.