Placement prep · DSA problem bank
Coding interview problems, explained and visualised
109 classic problems asked in placement coding rounds, from TCS and Infosys drives to Amazon-style product-company interviews. Each page gives you the key insight in plain words, a step-by-step approach, tested Python code, the common mistakes, and a free playground that shows the pattern running.
24 Easy · 76 Medium · 9 Hard · grouped by pattern, easiest first
#️⃣ Arrays & Hashing 12 problems
Hash maps, prefix sums and running totals: turn a nested loop into one pass. Pattern playground: Hash Tables Free
Two Sum
For every number x, the partner you need is fixed: target - x.
Contains Duplicate
A duplicate means "I have seen this value before". A hash set remembers everything seen so far and answers membership in O(1), so the first time a…
Valid Anagram
Order does not matter, only how many of each character. So build a frequency count for one string, subtract the other, and check that every count…
Best Time to Buy and Sell Stock
If you sell on day j, the best buy day is just the cheapest day before j.
Group Anagrams
All anagrams share a signature: the same letters with the same counts.
Longest Consecutive Sequence
Put every value in a hash set. A number x is the start of a run only if x - 1 is not in the set.
Subarray Sum Equals K
The sum of a subarray from i+1 to j is prefix[j] - prefix[i].
Product of Array Except Self
The product of everything except nums[i] is (product of everything to the left of i) times (product of everything to the right of i).
Maximum Subarray (Kadane's Algorithm)
Walk left to right and keep the best sum of a subarray that ends here.
Maximum Product Subarray
This is Kadane with a twist: multiplying by a negative number turns the smallest product into the largest.
Sort Colors (Dutch National Flag)
This is quicksort's partition step with pivot 1, done three ways.
Sort an Array (Merge Sort vs Quicksort)
Merge sort splits the list in half, sorts each half recursively, and merges two sorted halves by repeatedly taking the smaller front element.
↔️ Two Pointers 6 problems
Two indices walking toward each other (or in step) replace an O(n²) pair search. Pattern playground: Two Pointers Free
Valid Palindrome
A palindrome mirrors around its centre, so compare the outermost characters and move inward.
Move Zeroes
Use two pointers moving in the same direction: a read pointer that visits every element and a write pointer that marks where the next non-zero…
Two Sum II (Sorted Array)
Because the list is sorted, put one pointer on the smallest value and one on the largest.
3Sum
Sort the list. Fix the first number a = nums[i]; now you need two numbers to the right that sum to -a, which is Two Sum II on a sorted range,…
Container With Most Water
Start with the widest container, the two ends. The area is limited by the shorter wall.
Trapping Rain Water
The water above bar i is min(tallest bar to its left, tallest bar to its right) - height[i].
🪟 Sliding Window 7 problems
Grow the right edge, shrink the left edge, and keep the window valid in one sweep. Pattern playground: Sliding Window Free
Maximum Sum Subarray of Size K
Two neighbouring windows share k - 1 elements. Instead of re-adding all k, take the previous window's sum, add the element that enters on the…
Longest Substring Without Repeating Characters
Keep a window [left, right] that never contains a repeat. Grow it one character at a time on the right.
Minimum Size Subarray Sum
Since every number is positive, growing the window always increases its sum and shrinking always decreases it.
Longest Repeating Character Replacement
A window can be turned into one letter if the characters that are not its most frequent letter number at most k, that is window_length - max_count…
Permutation in String
A permutation of s1 is any string with the same letter counts and the same length.
Minimum Window Substring
Expand the right edge until the window covers t, then shrink the left edge as far as it can go while still covering it, recording the smallest window.
Sliding Window Maximum
Keep a deque of indices whose values are in decreasing order.
🔍 Binary Search 7 problems
Halve a sorted range, or a range of possible answers, every step. Pattern playground: Binary Search Free
Binary Search
Because the list is sorted, one comparison with the middle element tells you which half cannot contain the target.
Search Insert Position
The answer is the first index whose value is at least the target, often called the lower bound.
Find First and Last Position of an Element
Run binary search twice, each time looking for a boundary rather than any match.
Search in Rotated Sorted Array
Cut a rotated array anywhere and at least one half is still perfectly sorted.
Find Minimum in Rotated Sorted Array
Compare the middle element with the last element. If nums[mid] > nums[hi], the drop (and the minimum) must be to the right of mid.
Search a 2D Matrix
Read row by row, the matrix is one long sorted list of m·n values.
Koko Eating Bananas (Binary Search on the Answer)
You are not searching an array; you are searching the range of possible answers, speeds from 1 to max(piles).
📚 Stack & Monotonic Stack 7 problems
Brackets, expressions and next-greater questions: the last thing in is the first thing you need. Pattern playground: Stacks & the Monotonic Stack Free
Valid Parentheses
The bracket that must close next is always the most recently opened one that is still open.
Next Greater Element
Elements that have not found their answer yet sit on a stack, and their values are decreasing from bottom to top.
Min Stack
The trouble is that popping the current minimum should reveal the previous minimum.
Evaluate Reverse Polish Notation
In postfix notation an operator always applies to the two most recent values that have not been used yet.
Daily Temperatures
Keep a stack of the days that are still waiting for a warmer day.
Online Stock Span
When a higher price arrives, the smaller prices before it can never stop a future span: anything that would reach them reaches today first.
Largest Rectangle in Histogram
The best rectangle uses some bar as its shortest bar, and stretches left and right until it hits a shorter one.
🔗 Linked Lists 8 problems
Pointer rewiring, fast and slow pointers, and dummy heads. Pattern playground: Linked Lists: Reverse & Floyd's Cycle Free
Reverse Linked List
Walk the list once and flip one arrow per step. The danger is that flipping cur.next loses the rest of the list, so save it in nxt first.
Linked List Cycle (Floyd's Algorithm)
Send two runners down the list: the tortoise moves one step at a time, the hare two.
Middle of the Linked List
If one pointer moves twice as fast as another, then when the fast one reaches the end, the slow one is exactly halfway.
Merge Two Sorted Lists
The smallest remaining value is always at the front of one of the two lists.
Linked List Cycle II (Find Where the Cycle Starts)
First detect the cycle with Floyd's slow and fast pointers. Then the neat part: if the head is a steps from the cycle start, the meeting point is…
Remove Nth Node From End of List
Put two pointers n nodes apart and move them together. When the front one reaches the last node, the back one is sitting just before the node to…
Reorder List
The pattern takes from the front and the back alternately, but a singly linked list cannot walk backwards.
Add Two Numbers (Linked Lists)
Reverse order is a gift: the lists start at the ones digit, exactly where column addition starts.
🌳 Trees & BSTs 11 problems
Recursion on left and right subtrees, traversal orders and the BST ordering rule. Pattern playground: Binary Search Tree & Traversals Free
Binary Tree Inorder, Preorder & Postorder Traversal
All three traversals are the same depth-first walk; they only differ in when you write down the current node: before its children (pre), between…
Maximum Depth of Binary Tree
A tree's depth is one more than the deeper of its two subtrees.
Invert Binary Tree
Mirroring a tree means swapping the two children of every single node.
Balanced Binary Tree
The naive approach recomputes heights from scratch at every node.
Diameter of Binary Tree
Every path has one highest node where it bends. If the path bends at node X, its length is height(left of X) + height(right of X).
Binary Tree Level Order Traversal
Depth-first walks dive down one branch, but here you want the tree in rings by distance from the root, which is exactly what breadth-first search…
Validate Binary Search Tree
Comparing each node only with its direct children is the classic trap: a value deep in the right subtree can still be smaller than an ancestor.
Kth Smallest Element in a BST
An inorder traversal of a BST visits values in sorted order.
Lowest Common Ancestor of a BST
The BST ordering tells you where both nodes live without searching.
Lowest Common Ancestor of a Binary Tree
Ask every subtree one question: "do you contain p or q?" and have it return the node it found (or None).
Binary Tree Right Side View
The visible node on each level is just the last node of that level in a level order traversal.
🔺 Heaps & Top-K 6 problems
Keep the smallest or largest few items on top in O(log n) per update. Pattern playground: Binary Heap & Priority Queue Free
Kth Largest Element in a Stream
You only ever care about the top k values. Keep exactly those in a min-heap: its root is the smallest of the top k, which is the k-th largest overall.
Kth Largest Element in an Array
The k-th largest is the element that would sit at index n - k if the list were sorted.
Top K Frequent Elements
This is two small problems. First, count every value with a hash map in one pass.
K Closest Points to Origin
You want the k smallest distances, so keep a heap of size k whose root is the largest distance kept so far: the first one to evict when something…
Merge K Sorted Lists
The next node of the answer is always the smallest of the k current heads.
Find Median from Data Stream
Split the numbers into a lower half and an upper half. Keep the lower half in a max-heap (its root is the largest small number) and the upper half…
🗺️ Graphs & Grids 14 problems
BFS, DFS, topological order, union-find, Dijkstra and minimum spanning trees. Pattern playground: Graph Search: BFS vs DFS Free
Flood Fill
This is the paint-bucket tool. The region to repaint is the connected component of cells sharing the start colour, so a BFS or DFS from the start…
Number of Islands
Treat the grid as a graph where each land cell links to its land neighbours; an island is a connected component.
Max Area of Island
This is Number of Islands with one extra counter. Every time the scan finds unseen land, flood the whole island exactly as before, but count the…
Rotting Oranges
Rot spreads in rings, exactly like BFS layers. The key move is multi-source BFS: put every rotten orange in the queue at time 0, then process the…
01 Matrix (Distance to the Nearest Zero)
Running a BFS from every 1 to find its nearest 0 repeats a lot of work.
Shortest Path in a Binary Matrix
Every move costs the same, so this is an unweighted shortest path, and BFS is the right tool: it explores cells in order of distance, so the first…
Course Schedule
Draw an arrow from each prerequisite to the course that needs it.
Course Schedule II
Kahn's algorithm already produces the order: the sequence in which courses become unblocked and leave the queue is a topological order.
Number of Provinces
A province is a connected component. Union-Find answers it directly: start with every city as its own group (n groups), and for each connection…
Redundant Connection
Add the edges one at a time with Union-Find. An edge whose two endpoints are already in the same set closes a cycle, because a path between them…
Network Delay Time
Each node receives the signal at its shortest-path distance from k, so the answer is the largest of those distances.
Path With Minimum Effort
This is a shortest-path problem where a path's cost is the maximum step, not the sum.
Min Cost to Connect All Points
The cheapest way to connect everything, with no wasted links, is a minimum spanning tree.
Word Ladder
Hidden inside is a graph: each word is a node, and two words are connected if they differ in exactly one letter.
🪙 Dynamic Programming 13 problems
Define a sub-problem, write the recurrence, fill the table in the right order. Pattern playground: Coin Change (DP) Free
Climbing Stairs
Think about the last move. To stand on step n you arrived either from step n-1 (a 1-step) or from step n-2 (a 2-step).
House Robber
At each house you make one decision: take it (then you add its money to the best total from two houses back) or skip it (then you keep the best…
Coin Change (Fewest Coins)
The best way to make amount a ends with some last coin c, and what remains, a - c, must itself be made optimally.
Coin Change II (Number of Ways)
To count combinations rather than orderings, decide coins one denomination at a time.
Word Break
It is coin change with words as coins. Let ok[i] mean "the first i characters can be segmented".
0/1 Knapsack
Build a table where dp[i][w] is the best value using only the first i items with capacity w.
Partition Equal Subset Sum
If the total is S, the two groups must each sum to S / 2. So the question becomes: is there a subset that sums to S / 2?
Target Sum
Call the numbers with a plus sign P and the rest N. Then sum(P) - sum(N) = target and sum(P) + sum(N) = total, so sum(P) = (total + target) / 2.
Longest Common Subsequence
Compare the last characters of two prefixes. If they match, that character extends the LCS of both shorter prefixes: dp[i-1][j-1] + 1.
Edit Distance (Levenshtein Distance)
Let dp[i][j] be the cost to turn the first i characters of a into the first j of b.
Longest Increasing Subsequence
The classic DP says lis[i] = 1 + max(lis[j]) over earlier j with a smaller value, which is O(n²).
Unique Paths
The only ways into a cell are from the cell above or the cell to the left.
Longest Palindromic Substring
A palindrome is a palindrome with one matching character added on each side.
🧩 Backtracking 8 problems
Choose, explore, un-choose: generate every candidate and prune the dead ends. Pattern playground: Backtracking: Subsets, Permutations & Pruning Free
Subsets (Power Set)
Every element faces one yes-or-no question: in or out? Backtracking walks that decision tree.
Permutations
Fill the positions one at a time. For the next position you may place any number not yet used.
Combination Sum
Build combinations in non-decreasing index order so each combination is generated once.
Generate Parentheses
Do not generate all 22n strings and filter. Build the string left to right and only make legal moves: you may add ( while you have used fewer than…
Letter Combinations of a Phone Number
Each digit is one level of the recursion tree, and its letters are the branches.
Word Search
Start a depth-first search from every cell that matches the first letter.
Palindrome Partitioning
Choose where the first piece ends. If that prefix is a palindrome, keep it and partition the rest of the string the same way; if not, that branch…
N-Queens
Every row must hold exactly one queen, so place them one row at a time.
📅 Intervals 6 problems
Sort by start or end, then sweep once. Pattern playground: Merge Intervals & Meeting Rooms Free
Meeting Rooms
Sort the meetings by start time. If any two meetings overlap, then some meeting overlaps the one right after it in sorted order.
Merge Intervals
After sorting by start, any interval that overlaps the current merged block must come right after it.
Insert Interval
Because the list is already sorted, it splits into three runs: intervals that end before the new one starts (copy them), intervals that overlap it…
Meeting Rooms II (Minimum Rooms)
The number of rooms needed is the largest number of meetings running at the same moment.
Non-overlapping Intervals
Removing the fewest is the same as keeping the most. The classic activity-selection greedy keeps the interval that ends earliest, because it…
Minimum Number of Arrows to Burst Balloons
Sort balloons by end. The balloon that ends first must be hit by some arrow, and shooting at its end is the best choice, because it is as far…
🗃️ Design & Tries 4 problems
Combine data structures so every operation hits its target complexity. Pattern playground: LRU Cache (HashMap + Linked List) Free
LRU Cache
You need two things at once: find any key instantly (a hash map does that) and know the recency order so you can drop the oldest (a list does that).
Implement Trie (Prefix Tree)
A trie stores words as paths of characters from a root. Words that share a beginning share the same nodes, so a prefix is stored once.
Design Add and Search Words (Wildcard Trie)
Store words in a trie. A normal letter follows one child, as usual.
Word Search II
Running Word Search once per word repeats the same exploration for words that share prefixes.
Frequently asked questions
Which coding interview problems should I practise first?
Start with the Easy problems in Arrays & Hashing, Two Pointers and Sliding Window, then Binary Search, Stack and Linked Lists. Trees, graphs and dynamic programming build on those patterns.
Are these the same as LeetCode problems?
They are the classic problems that interview-prep communities know by these common names. The statements, explanations and solutions here are written in our own words, and each solution is tested.
How do the interactive visuals help?
Each problem links to a free in-browser playground that animates its core pattern, such as BFS flooding a grid or a DP table filling cell by cell. Seeing the pattern run makes it much easier to recognise in a new problem.
Is this enough for TCS, Infosys or Amazon coding rounds?
These patterns cover most of the data-structures and algorithms questions in service-company and product-company coding rounds. Pair them with timed practice and the placement prep guides for your specific drive.
Preparing for placements?
Take the 2-minute readiness check to find your weak patterns, then follow the placement path from DSA core to system design.
Placement prep guides Amazon SDE pattern map TCS NQT All playgrounds
Problem statements on this site are written in our own words. Problem names are the common names used across interview-prep communities; BitBootcamp is an independent learning platform and is not affiliated with LeetCode or any company that asks these questions.