Two Sum
The hash table trick that makes O(n²) become O(n) and why this pattern appears everywhere from feature stores to embedding lookups.
A comprehensive collection of data structures and algorithms problems, from fundamentals to advanced topics. Each problem explores multiple solutions, complexity analysis, and real-world applications.
Each problem includes:
Arrays & Hash Tables:
Stacks:
Linked Lists:
Design:
Dynamic Programming:
Trees & Graphs:
Sorting & Searching:
Two Pointers & Greedy:
Backtracking:
String Manipulation & Hash Tables:
Intervals:
Matrix & In-place Algorithms:
Below you’ll find all DSA problems in chronological order:
Content created with the assistance of large language models and reviewed for technical accuracy.
The hash table trick that makes O(n²) become O(n) and why this pattern appears everywhere from feature stores to embedding lookups.
Why a simple stack solves bracket matching, expression parsing, and even neural network depth management in one elegant pattern.
The pointer manipulation pattern that powers merge sort, data pipeline merging, and multi-source stream processing.
The single-pass pattern that powers streaming analytics, online algorithms, and real-time decision making in production systems.
Master the pattern behind online algorithms, streaming analytics, and dynamic programming, a single elegant idea powering countless production systems.
The Fibonacci problem in disguise, teaching the fundamental transition from recursion to dynamic programming to space optimization.
Master the fundamental patterns of tree traversal: the gateway to solving hundreds of tree problems in interviews.
Master BST validation to understand data integrity in tree structures, critical for indexing and search systems.
Master binary search to understand logarithmic algorithms and efficient searching, foundational for optimization and search systems.
Master linked list manipulation through reversal - a fundamental pattern for understanding pointer logic and in-place algorithms.
Master LRU cache design: O(1) get/put with hash map + doubly linked list. Critical for interviews and production caching systems.
Master digit-by-digit addition with linked lists: Handle carry propagation elegantly. Classic problem teaching pointer manipulation and edge cases.
Master the two-pointer greedy technique that powers resource optimization in production ML systems.
Master backtracking to generate all valid combinations—the foundation of ensemble model selection and multi-model systems.
Master hash-based grouping to solve anagrams—the foundation of clustering systems and speaker diarization in production ML.
Master interval processing to handle overlapping ranges—the foundation of event streams and temporal reasoning in production systems.
Simulate arbitrary-precision addition on linked lists—the same sequential pattern used in large-scale distributed training and streaming pipelines.
Master in-place matrix rotation—the same 2D transformation pattern that powers image and spectrogram augmentations in modern ML systems.
Master systematic matrix traversal—the same pattern used for tracking experiments, processing logs, and managing state in ML systems.
Master greedy decision-making to determine reachability—the same adaptive strategy used in online learning and real-time speech systems.
Master grid path counting with dynamic programming—the same optimization technique used in neural architecture search and speech model design.
The classic grid optimization problem that bridges the gap between simple recursion and 2D Dynamic Programming.
A deceptive counting problem that teaches the fundamentals of state transitions and connects directly to Beam Search.
The fundamental string segmentation problem that powers spell checkers, search engines, and tokenizers.
The gatekeeper of data integrity. How do we ensure our sorted structures are actually sorted?
How do you print a corporate hierarchy level by level? CEO first, then VPs, then Managers…
Given two arrays, can you rebuild the original tree? It’s like solving a jigsaw puzzle where the pieces are numbers.
Finding the median or the 99th percentile is easy in a sorted array. Can we do it in a tree?
“Find the point where two paths in a tree first meet.”
“Counting connected components in a 2D grid.”
“Can you finish all courses given their prerequisites?”
“Transforming ‘cold’ to ‘warm’ one letter at a time.”
“Creating a deep copy of a graph structure.”
“Modeling algebraic equations as graph path problems.”
“Capturing regions by identifying safe boundaries.”
“Can you split the treasure evenly?”
“Finding the longest upward trend in chaos.”
“Making change with the fewest coins.”
“Making sense of a stream of characters.”
“Calculating capacity in a fragmented landscape.”
“Finding the optimal path through a sequence of choices.”
“Combining order from chaos, one element at a time.”
“Finding the middle ground between two ordered worlds.”
“Finding the maximum hidden in the valleys and peaks.”
“Finding the king of every window.”
“Find the path to success—even if you have to start from the bottom, go up, and come back down.”
“Data is only useful if it can survive the journey from RAM to Disk and back again.”
“Don’t look for one needle in a haystack. Magnetize the hay to find all needles at once.”
“You can’t build the roof before you pour the foundation.”
“Language is just a graph of symbols. If you know the order, you know the language.”
“Stop thinking ‘merge’. Think ‘partition’—the median is just the boundary between two halves.”
“Water doesn’t care about every bar—only the highest walls to the left and right.”
“The missing number is hiding in plain sight—use the array itself as the hash table.”
“Wildcard matching is more than a string puzzle—it is the foundation of every file system glob, every firewall rule, and every log-routing engine you use tod...
“The N-Queens problem is the ‘Hello World’ of constraint satisfaction—it teaches us how to prune the search tree before it consumes our CPU.”
“Minimum Window Substring is the crown jewel of the sliding window pattern—it teaches us how to find the smallest container that satisfies a complex set of r...
“Largest Rectangle in Histogram is the masterclass of the Monotonic Stack. It requires maintaining a sorted state of indices to solve a local minimum problem...
“Regular Expression Matching is where string manipulation meets automata theory. It requires translating a sequence of patterns into a resilient state machin...
“Sudoku Solver is the quintessential backtracking problem—it represents the transition from simple recursion to a multi-constraint search problem where every...
“Designing an LFU Cache is the ultimate exercise in composite data structures—it forces you to synchronize multiple hash maps and linked lists to achieve O(1...