Amazon coding interviews assess a candidate's proficiency in Data Structures, Algorithms, and problem-solving through topic-wise programming challenges. This sheet provides a structured collection of the most frequently asked Amazon coding questions organized by core DSA topics.
- Covers Amazon coding questions categorized by topics such as Arrays, Strings, Linked Lists, Trees, Graphs, Dynamic Programming, and more.
- Includes optimized solutions with detailed explanations to strengthen coding skills and interview preparation.
Array
An array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together.
- Largest Sum Contiguous Subarray
- Search in a row-wise and column-wise sorted matrix
- Print a given matrix in spiral form
- Program for array rotation
- Trapping Rain Water
- Count pairs with given sum
- Find the subarray with least average
- Convert array into Zig-Zag fashion
- Find duplicates in an array
- Find a triplet that sum to a given value
String
String are defined as an array of characters. The difference between a character array and a string is the string is terminated with a special character ‘\0’.
- Validate an IP Address
- Multiply Strings
- Implement Atoi
- Check if the string is rotated by two places
- Permutations of a given string
- Longest Repeating Subsequence
- Roman Number to Integer
- Length of the longest substring
- String formation from substring
- Check whether two strings are an anagram of each other
- Look-and-Say Sequence
- Remove minimum number of characters so that two strings become anagram
- Find the smallest window in a string containing all characters of another string
- Length of the longest substring without repeating characters
Linked List
Linked List is the data structure that can overcome all the limitations of an array. A Linked list is a linear data structure, in which the elements are not stored at contiguous memory locations, it allocates memory dynamically.
- Reverse a linked list
- Segregate even and odd nodes in a Linked List
- Detect loop in a linked list
- Delete all occurrences of a given key in a linked list
- Remove loop in Linked List
- Nth node from the end of linked list
- Merge K sorted linked lists
- Flatten a binary tree into linked list
- Add two numbers represented by linked lists
- Function to check if a singly linked list is palindrome
- Clone a linked list with next and random pointer
- Delete without head pointer
- Given a linked list of 0s, 1s and 2s, sort it
- Intersection of Two Linked Lists
Searching
Searching Algorithms are designed to check for an element or retrieve an element from any data structure where it is stored.
- Search an element in a sorted and rotated array
- Square root of an integer
- First and last occurrences of x
- Find a peak element
- Find the smallest positive number missing from an unsorted array
- Allocate minimum number of pages
- Counting elements in two arrays
- Median of two sorted arrays of different sizes
Sorting
A Sorting Algorithm is used to rearrange a given array or list of elements according to a comparison operator on the elements. The comparison operator is used to decide the new order of elements in the respective data structure.
- k largest(or smallest) elements in an array
- Sort an array of 0s, 1s, and 2s
- Count Inversions in an array
- Merge Without Extra Space
- Minimum Platforms
- Quick Sort
- Heap Sort
- Merge k Sorted Arrays
- Overlapping Intervals
Stack
A stack is a linear data structure in which elements can be inserted and deleted only from one side of the list, called the top. A stack follows the LIFO (Last In First Out) principle.
- Check for Balanced Brackets in an expression (well-formedness) using Stack
- Sort a stack using recursion
- The Celebrity Problem
- Next Greater Element
- Queue using two Stacks
Queue
A Queue is a linear data structure in which elements can be inserted only from one side of the list called rear, and the elements can be deleted only from the other side called the front. The queue data structure follows the FIFO (First In First Out) principle.
- Stack using two queues
- Connect n ropes with minimum cost
- Minimum time required to rot all oranges
- First negative integer in every window of size k
- Reversing a Queue
Tree
A tree is non-linear and a hierarchical data structure consisting of a collection of nodes such that each node of the tree stores a value, a list of references to nodes (the “children”).
- Inorder Traversal
- Preorder Traversal
- Kth largest element in BST
- Left View of Binary Tree
- Right View of Binary Tree
- Check for BST
- Diameter of a Binary Tree
- Boundary Traversal of binary tree
- Height of Binary Tree
- Lowest Common Ancestor in a Binary Tree
- Binary Tree to DLL
- Root to leaf path sum
- Reverse Level Order Traversal
- Construct Tree from Inorder & Preorder
- ZigZag Tree Traversal
- Serialize and Deserialize a Binary Tree
Graph
A Graph is a non-linear data structure consisting of nodes and edges. The nodes are sometimes also referred to as vertices and the edges are lines or arcs that connect any two nodes in the graph.
- BFS of Graph
- DFS of Graph
- Find the number of islands
- Topological sort
- Steps by Knight
- Strongly Connected Components (Kosaraju's Algo)
- Alien Dictionary
- Dijkstra Algorithm
- Detect Cycle in a Directed Graph
- Detect cycle in an undirected graph
Trie
Trie is an efficient information retrieval data structure. Using Trie, search complexities can be brought to optimal limit (key length).
- Trie Insert and Search
- Trie Delete
- Print unique rows in a given Binary matrix
- Longest Common Prefix using Trie
- Minimum XOR Value Pair
- Palindrome pair in an array of words (or strings)
Heap and Hash
A Heap is a special Tree-based data structure in which the tree is a complete binary tree. Heap and hash is an efficient implementation of a priority queue. The linear hash function monotonically maps keys to buckets, and each bucket is a heap.
- Minimum Cost of ropes
- k largest elements
- Kth element in Matrix
- Find median in a stream
- Kth largest element in a stream
- Rearrange characters
- Nearly sorted
- Nuts and Bolts Problem
- Check if two strings are k-anagrams or not
- Sort an array according to the other
- Swapping pairs make sum equal
- Smallest distinct window
- Find first repeated character
BitMagic
Bit stands for binary digit. A bit is the basic unit of information and can only have one of two possible values that is 0 or 1.
- Find the Missing Number
- Power of 2
- Reverse Bits
- Maximum subset XOR
- Check set bits
- Minimum X (xor) A
- Longest Consecutive 1's
- Number of 1 Bits
Recursion and Backtracking
Recursion: The process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called a recursive function.
Backtracking: Backtracking is an algorithmic technique for solving problems recursively by trying to build a solution incrementally, one piece at a time, removing those solutions that fail to satisfy the constraints of the problem at any point in time (by time, here, is referred to the time elapsed till reaching any level of the search tree).
- Write a program to print all permutations of a given string
- Rat in a Maze Problem - I
- Josephus problem
- Combination Sum
- Partition Equal Subset Sum
- N-Queen Problem
- Shuffle integers
- Hamiltonian Path
- Find the string in grid
- Pascal Triangle
- Solve the Sudoku
- Largest number in K swaps
Dynamic Programming
Dynamic Programming is mainly an optimization over plain recursion. Wherever we see a recursive solution that has repeated calls for same inputs, we can optimize it using Dynamic Programming.
- 0 - 1 Knapsack Problem
- Partition Equal Subset Sum
- Coin Change
- Longest Common Subsequence
- Stock buy and sell
- Interleaved Strings
- Edit Distance
- Stickler Thief
- Longest Common Substring
- Number of Coins
- Egg Dropping Puzzle
- Word Break
- Wildcard Pattern Matching
- Total Decoding Messages
- Jump Game
- Special Keyboard
- Longest Palindromic Subsequence