Amazon Programming Interview Questions

Subscribe for free interview question feeds

Leave your Email to get the latest Amazon interview questions weekly.
We'll never share your email with anyone else.
No spam we promise.

Most Frequently Asked Amazon Programming Interview Questions
167 Two Sum II - Input array is sorted Easy
78 Subsets Medium
89 Gray Code Medium
199 Binary Tree Right Side View Medium
23 Merge k Sorted Lists Hard
200 Number of Islands Medium
5 Longest Palindromic Substring Medium
8 String to Integer (atoi) Medium
49 Group Anagrams Medium
98 Validate Binary Search Tree Medium
102 Binary Tree Level Order Traversal Medium
48 Rotate Image Medium
236 Lowest Common Ancestor of a Binary Tree Medium
240 Search a 2D Matrix II Medium
239 Sliding Window Maximum Hard
121 Best Time to Buy and Sell Stock Easy
234 Palindrome Linked List Easy
238 Product of Array Except Self Medium
204 Count Primes Easy
235 Lowest Common Ancestor of a Binary Search Tree Easy
297 Serialize and Deserialize Binary Tree Hard
186 Reverse Words in a String II Medium
160 Intersection of Two Linked Lists Easy
20 Valid Parentheses Easy
138 Copy List with Random Pointer Medium
42 Trapping Rain Water Hard
141 Linked List Cycle Easy
127 Word Ladder Medium
242 Valid Anagram Easy
126 Word Ladder II Hard
215 Kth Largest Element in an Array Medium
139 Word Break Medium
21 Merge Two Sorted Lists Easy
2 Add Two Numbers Medium
206 Reverse Linked List Easy
3 Longest Substring Without Repeating Characters Medium
15 3Sum Medium
146 LRU Cache Hard
17 Letter Combinations of a Phone Number Medium
1 Two Sum Easy
155 Min Stack Easy
355 Design Twitter Medium
380 Insert Delete GetRandom O(1) Medium
396 Rotate Function Medium
387 First Unique Character in a String Easy
414 Third Maximum Number Easy
73 Set Matrix Zeroes Medium
438 Find All Anagrams in a String Easy
119 Pascal's Triangle II Easy
451 Sort Characters By Frequency Medium
449 Serialize and Deserialize BST Medium
459 Repeated Substring Pattern Easy
460 LFU Cache Hard
508 Most Frequent Subtree Sum Medium
516 Longest Palindromic Subsequence Medium
517 Super Washing Machines Hard
529 Minesweeper Medium
532 K-diff Pairs in an Array Easy
535 Encode and Decode TinyURL Medium
536 Construct Binary Tree from String Medium
538 Convert BST to Greater Tree Easy
537 Complex Number Multiplication Medium
545 Boundary of Binary Tree Medium
553 Optimal Division Medium
579 Find Cumulative Salary of an Employee Hard
606 Construct String from Binary Tree Easy
617 Merge Two Binary Trees Easy
640 Solve the Equation Medium
645 Set Mismatch Easy
646 Maximum Length of Pair Chain Medium
661 Image Smoother Easy
662 Maximum Width of Binary Tree Medium
663 Equal Tree Partition Medium
675 Cut Off Trees for Golf Event Hard
682 Baseball Game Easy
694 Number of Distinct Islands Medium
692 Top K Frequent Words Medium
711 Number of Distinct Islands II Hard
189 Rotate Array Easy
725 Split Linked List in Parts Medium
738 Monotone Increasing Digits Medium
742 Closest Leaf in a Binary Tree Medium
746 Min Cost Climbing Stairs Easy
762 Prime Number of Set Bits in Binary Representation Easy
763 Partition Labels Medium
771 Jewels and Stones Easy
775 Global and Local Inversions Medium
776 Split BST Medium
791 Custom Sort String Medium
801 Minimum Swaps To Make Sequences Increasing Medium
819 Most Common Word Easy
842 Split Array into Fibonacci Sequence Medium
851 Loud and Rich
979 Distribute Coins in Binary Tree Medium
890 Find and Replace Pattern Medium
895 Maximum Frequency Stack Hard
899 Orderly Queue Hard
900 RLE Iterator Medium
902 Numbers At Most N Given Digit Set Hard
904 Fruit Into Baskets Medium
905 Sort Array By Parity Easy
909 Snakes and Ladders Medium
919 Complete Binary Tree Inserter Medium
922 Sort Array By Parity II Easy
929 Unique Email Addresses Easy
937 Reorder Data in Log Files Easy
938 Range Sum of BST Easy
939 Minimum Area Rectangle Medium
942 DI String Match Easy
943 Find the Shortest Superstring Hard
951 Flip Equivalent Binary Trees Medium
953 Verifying an Alien Dictionary Easy
957 Prison Cells After N Days Medium
958 Check Completeness of a Binary Tree Medium
963 Minimum Area Rectangle II Medium
966 Vowel Spellchecker Medium
969 Pancake Sorting Medium
973 K Closest Points to Origin Medium
974 Subarray Sums Divisible by K Medium
977 Squares of a Sorted Array Easy
978 Longest Turbulent Subarray Medium
980 Unique Paths III Hard
981 Time Based Key-Value Store Medium
983 Minimum Cost For Tickets Medium
986 Interval List Intersections Medium
987 Vertical Order Traversal of a Binary Tree Medium
992 Subarrays with K Different Integers Hard
993 Cousins in Binary Tree Easy
994 Rotting Oranges Easy
995 Minimum Number of K Consecutive Bit Flips Hard
997 Find the Town Judge Easy
1000 Minimum Cost to Merge Stones Hard
1002 Find Common Characters Easy
1004 Max Consecutive Ones III Medium
1005 Maximize Sum Of Array After K Negations Easy
1007 Minimum Domino Rotations For Equal Row Medium
1008 Construct Binary Search Tree from Preorder Traversal Medium
1010 Pairs of Songs With Total Durations Divisible by 60 Easy
1011 Capacity To Ship Packages Within D Days Medium
1019 Next Greater Node In Linked List Medium
1022 Sum of Root To Leaf Binary Numbers Easy
1023 Camelcase Matching Medium
1024 Video Stitching Medium
1026 Maximum Difference Between Node and Ancestor Medium
1028 Recover a Tree From Preorder Traversal Hard
1029 Two City Scheduling Easy
1031 Maximum Sum of Two Non-Overlapping Subarrays Medium
1032 Stream of Characters Hard
1035 Uncrossed Lines Medium
1038 Binary Search Tree to Greater Sum Tree Medium
1044 Longest Duplicate Substring Hard
1045 Customers Who Bought All Products Medium
1046 Last Stone Weight Easy
1047 Remove All Adjacent Duplicates In String Easy
1049 Last Stone Weight II Medium
1050 Actors and Directors Who Cooperated At Least Three Times Easy
1051 Height Checker Easy
1054 Distant Barcodes Medium
1057 Campus Bikes Medium
1060 Missing Element in Sorted Array Medium
1062 Longest Repeating Substring Medium
1065 Index Pairs of a String Easy
1066 Campus Bikes II Medium
1067 Digit Count in Range Hard
1068 Product Sales Analysis I Easy
1069 Product Sales Analysis II Easy
1070 Product Sales Analysis III Medium
1074 Number of Submatrices That Sum to Target Hard
1080 Insufficient Nodes in Root to Leaf Paths Medium
1082 Sales Analysis I Easy
1083 Sales Analysis II Easy
1084 Sales Analysis III Easy
1085 Sum of Digits in the Minimum Number Easy
1086 High Five Easy
1091 Shortest Path in Binary Matrix Medium
1094 Car Pooling Medium
1099 Two Sum Less Than K Easy
1100 Find K-Length Substrings With No Repeated Characters Medium
1102 Path With Maximum Minimum Value Medium
1104 Path In Zigzag Labelled Binary Tree Medium
1108 Defanging an IP Address Easy
1114 Print in Order Easy
1118 Number of Days in a Month Easy
1119 Remove Vowels from a String Easy
1120 Maximum Average Subtree Medium
1122 Relative Sort Array Easy
1128 Number of Equivalent Domino Pairs Easy
1129 Shortest Path with Alternating Colors Medium
1130 Minimum Cost Tree From Leaf Values Medium
1133 Largest Unique Number Easy
1134 Armstrong Number Easy
1135 Connecting Cities With Minimum Cost Medium
1143 Longest Common Subsequence Medium
1152 Analyze User Website Visit Pattern Medium
1155 Number of Dice Rolls With Target Sum Medium
1160 Find Words That Can Be Formed by Characters Easy
1161 Maximum Level Sum of a Binary Tree Medium
1162 As Far from Land as Possible Medium
1167 Minimum Cost to Connect Sticks Medium
1172 Dinner Plate Stacks Hard
1175 Arrangements Easy
1176 Diet Plan Performance Easy
1179 Reformat Department Table Easy
1188 Design Bounded Blocking Queue Medium
1192 Critical Connections in a Network
1197 Minimum Knight Moves Medium
1202 Smallest String With Swaps Medium
1214 Two Sum BSTs Medium
1219 Path with Maximum Gold Medium
1229 Meeting Scheduler Medium
1233 Remove Sub-Folders from the Filesystem Medium
1236 Web Crawler Medium
1249 Minimum Remove to Make Valid Parentheses Medium
1251 Average Selling Price Easy
1255 Maximum Score Words Formed by Letters Hard
1259 Handshakes That Don't Cross Hard
1260 Shift 2D Grid Easy
1268 Search Suggestions System Medium
1275 Find Winner on a Tic Tac Toe Game Easy
1279 Traffic Light Controlled Intersection Easy
1288 Remove Covered Intervals Medium
1299 Replace Elements with Greatest Element on Right Side Easy
1303 Find the Team Size Easy
1305 All Elements in Two Binary Search Trees Medium
1311 Get Watched Videos by Your Friends Medium
1315 Sum of Nodes with Even-Valued Grandparent Medium
1325 1325. Delete Leaves With a Given Value Medium
1327 List the Products Ordered in a Period Easy
1332 Remove Palindromic Subsequences Easy
1337 The K Weakest Rows in a Matrix Easy
1350 Students With Invalid Departments Easy
1351 Count Negative Numbers in a Sorted Matrix Easy
1362 Closest Divisors Medium
1363 Largest Multiple of Three Hard
1373 Maximum Sum BST in Binary Tree Hard
1382 Balance a Binary Search Tree Medium
1395 Count Number of Teams Medium
1404 Number of Steps to Reduce a Number in Binary Representation to One Medium
1408 String Matching in an Array Easy
1409 Queries on a Permutation With Key Medium
1429 First Unique Number Medium
1456 Maximum Number of Vowels in a Substring of Given Length Medium
1457 Pseudo-Palindromic Paths in a Binary Tree Medium
1479 Sales by Day of the Week Hard
1485 Clone Binary Tree With Random Pointer Medium
1489 Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree Hard
1496 Path Crossing Easy
1502 Can Make Arithmetic Progression From Sequence Easy
1520 Maximum Number of Non-Overlapping Substrings Hard
1558 Minimum Numbers of Function Calls to Make Target Array Medium
1574 Shortest Subarray to be Removed to Make Array Sorted Medium
1601 Maximum Number of Achievable Transfer Requests Hard
1603 Design Parking System Easy
1613 Find the Missing IDs Medium
1621 Number of Sets of K Non-Overlapping Line Segments Medium
1623 All Valid Triplets That Can Represent a Country Medium
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...

Find Words in A Data Stream I

Design a data structure to return the next word in the dictionary...

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

Shortest Word Distance

Shortest Word Distance

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.