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.

Easy#️⃣ Hash Tables→

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…

Easy#️⃣ Hash Tables→

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…

Easy#️⃣ Hash Tables→

Best Time to Buy and Sell Stock

If you sell on day j, the best buy day is just the cheapest day before j.

Easy📈 Prefix Sums & Kadane→

Group Anagrams

All anagrams share a signature: the same letters with the same counts.

Medium#️⃣ Hash Tables→

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.

Medium#️⃣ Hash Tables→

Subarray Sum Equals K

The sum of a subarray from i+1 to j is prefix[j] - prefix[i].

Medium📈 Prefix Sums & Kadane→

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

Medium📈 Prefix Sums & Kadane→

Maximum Subarray (Kadane's Algorithm)

Walk left to right and keep the best sum of a subarray that ends here.

Medium📈 Prefix Sums & Kadane→

Maximum Product Subarray

This is Kadane with a twist: multiplying by a negative number turns the smallest product into the largest.

Medium📈 Prefix Sums & Kadane→

Sort Colors (Dutch National Flag)

This is quicksort's partition step with pivot 1, done three ways.

Medium🔀 Quicksort, Partition & Conquer→

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.

Medium🏁 Sorting Race→

↔️ Two Pointers 6 problems

Two indices walking toward each other (or in step) replace an O(n²) pair search. Pattern playground: Two Pointers Free

🪟 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

📚 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

🔗 Linked Lists 8 problems

Pointer rewiring, fast and slow pointers, and dummy heads. Pattern playground: Linked Lists: Reverse & Floyd's Cycle Free

🌳 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…

Easy🌳 Binary Search Tree & Traversals→

Maximum Depth of Binary Tree

A tree's depth is one more than the deeper of its two subtrees.

Easy🌳 Binary Search Tree & Traversals→

Invert Binary Tree

Mirroring a tree means swapping the two children of every single node.

Easy🌳 Binary Search Tree & Traversals→

Balanced Binary Tree

The naive approach recomputes heights from scratch at every node.

Easy🌳 Binary Search Tree & Traversals→

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

Easy🌳 Binary Search Tree & Traversals→

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…

Medium🌳 Binary Search Tree & Traversals→

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.

Medium🌳 Binary Search Tree & Traversals→

Kth Smallest Element in a BST

An inorder traversal of a BST visits values in sorted order.

Medium🌳 Binary Search Tree & Traversals→

Lowest Common Ancestor of a BST

The BST ordering tells you where both nodes live without searching.

Medium🌳 Binary Search Tree & Traversals→

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

Medium🌳 Binary Search Tree & Traversals→

Binary Tree Right Side View

The visible node on each level is just the last node of that level in a level order traversal.

Medium🌳 Binary Search Tree & Traversals→

🔺 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

🗺️ 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…

Easy🏝️ Number of Islands & Grid BFS→

Number of Islands

Treat the grid as a graph where each land cell links to its land neighbours; an island is a connected component.

Medium🏝️ Number of Islands & Grid BFS→

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…

Medium🏝️ Number of Islands & Grid BFS→

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…

Medium🏝️ Number of Islands & Grid BFS→

01 Matrix (Distance to the Nearest Zero)

Running a BFS from every 1 to find its nearest 0 repeats a lot of work.

Medium🏝️ Number of Islands & Grid BFS→

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…

Medium🏝️ Number of Islands & Grid BFS→

Course Schedule

Draw an arrow from each prerequisite to the course that needs it.

Medium🗂️ Topological Sort→

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.

Medium🗂️ Topological Sort→

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…

Medium🔗 Union-Find (DSU)→

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…

Medium🔗 Union-Find (DSU)→

Network Delay Time

Each node receives the signal at its shortest-path distance from k, so the answer is the largest of those distances.

Medium🧭 Dijkstra's Shortest Path→

Path With Minimum Effort

This is a shortest-path problem where a path's cost is the maximum step, not the sum.

Medium🧭 Dijkstra's Shortest Path→

Min Cost to Connect All Points

The cheapest way to connect everything, with no wasted links, is a minimum spanning tree.

Medium🌲 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.

Hard🗺️ Graph Search→

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

Easy🪆 Recursion & the Call Stack→

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…

Medium🪙 Coin Change (DP)→

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.

Medium🪙 Coin Change (DP)→

Coin Change II (Number of Ways)

To count combinations rather than orderings, decide coins one denomination at a time.

Medium🪙 Coin Change (DP)→

Word Break

It is coin change with words as coins. Let ok[i] mean "the first i characters can be segmented".

Medium🪙 Coin Change (DP)→

0/1 Knapsack

Build a table where dp[i][w] is the best value using only the first i items with capacity w.

Medium🎒 0/1 Knapsack (DP)→

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?

Medium🎒 0/1 Knapsack (DP)→

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.

Medium🎒 0/1 Knapsack (DP)→

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.

Medium🧮 2D DP Table→

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.

Medium🧮 2D DP Table→

Longest Increasing Subsequence

The classic DP says lis[i] = 1 + max(lis[j]) over earlier j with a smaller value, which is O(n²).

Medium🧮 2D DP Table→

Unique Paths

The only ways into a cell are from the cell above or the cell to the left.

Medium🧮 2D DP Table→

Longest Palindromic Substring

A palindrome is a palindrome with one matching character added on each side.

Medium🧮 2D DP Table→

🧩 Backtracking 8 problems

Choose, explore, un-choose: generate every candidate and prune the dead ends. Pattern playground: Backtracking: Subsets, Permutations & Pruning Free

📅 Intervals 6 problems

Sort by start or end, then sweep once. Pattern playground: Merge Intervals & Meeting Rooms Free

🗃️ Design & Tries 4 problems

Combine data structures so every operation hits its target complexity. Pattern playground: LRU Cache (HashMap + Linked List) Free

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.