Learning path · 52 lessons · 11 topics
⌨️ Coding Patterns (DSA) interview preparation
The patterns behind most coding rounds, solved in Java with complexity analysis.
Coding rounds reuse a small number of patterns. Recognising the pattern is most of the work: two pointers, sliding window, binary search, BFS/DFS, dynamic programming and heaps cover the majority of questions.
Work through the patterns in order. For each problem, try it yourself first, then read the brute-force and optimal solutions and their time and space complexity.
What you will learn
- Arrays, hashing, two pointers and sliding window
- Stacks, queues, binary search and linked lists
- Trees, graphs, heaps and intervals
- Dynamic programming and string problems
Topics
Roadmap: beginner to advanced
-
1
Beginner Beginner stage
Foundations: the concepts every interviewer expects you to explain clearly.
Arrays & Hashing
Two Pointers
- Check whether a string is a valid palindrome (ignoring case and non-alphanumerics). Compare StringBuilder, streams and two pointers.
- Remove duplicates from a sorted array in place (and move zeroes). Compare new collections, streams and read/write pointers.
Sliding Window
Binary Search
Linked List
Dynamic Programming
Strings
-
2
Intermediate Intermediate stage
Working knowledge: how things behave in real projects and the trade-offs you make.
Arrays & Hashing
- Two Sum: find two indices whose values add up to a target.
- Group anagrams together.
- Find the length of the longest consecutive sequence in an unsorted array. Compare sorting, HashSet and streams.
- Product of array except self without division. Show brute force, division and prefix/suffix products.
- Count subarrays whose sum equals K. Show brute force, prefix sums and the HashMap of prefix sums.
Two Pointers
- 3Sum: find all unique triplets that sum to zero. Show brute force, HashSet and sort + two pointers.
- Container with most water. Why does moving the shorter line work?
Sliding Window
- Find the length of the longest substring without repeating characters.
- Minimum size subarray with sum ≥ target (variable sliding window). Compare brute force, binary search and two pointers.
- Find all anagrams of a pattern in a string. Compare sorting each window, HashMap windows and fixed int[26] counts.
Stack & Queue
- Validate balanced brackets.
- Next greater element for every array element. Compare brute force and the monotonic stack.
- Design a stack that returns the minimum in O(1). Compare scanning, two stacks and encoded values.
Binary Search
Linked List
- Reverse a linked list, and detect a cycle in it.
- Remove the Nth node from the end of a linked list. Compare two passes, a list of nodes, and one pass with two pointers.
- Find where two linked lists intersect. Compare nested loops, HashSet, length difference and the pointer-switch trick.
Trees
- Return the level-order traversal of a binary tree, and its right side view.
- Find the lowest common ancestor of two nodes in a binary tree (and in a BST).
- Binary tree traversals (inorder, preorder, postorder). Compare recursion, an explicit stack and Morris traversal.
- Validate a binary search tree. Compare inorder list, recursive bounds and iterative inorder.
- Diameter of a binary tree. Compare recomputing heights and a single postorder pass.
Graphs
- Count the number of islands in a grid.
- Rotting oranges (multi-source BFS). Compare repeated simulation with level-order BFS.
Heaps & Intervals
- Find the top K most frequent elements.
- Merge overlapping intervals.
- Find the Kth largest element in an array.
- Meeting rooms II: minimum number of rooms. Compare counting overlaps, a min-heap and a sweep line.
Dynamic Programming
- Coin change: minimum number of coins to make an amount (dynamic programming).
- Maximum subarray sum. Compare brute force, divide and conquer, and Kadane's algorithm.
Strings
-
3
Advanced Advanced stage
Senior depth: internals, scale, failure modes and design decisions.
Two Pointers
Sliding Window
Stack & Queue
Binary Search
Linked List
Graphs
- Course schedule: detect cycles and produce a topological order.
- Shortest path in a weighted graph (network delay time). Compare BFS, Bellman-Ford and Dijkstra.
Heaps & Intervals
Dynamic Programming