Data Structures & Algorithms

Interview preparation for ML engineers and applied scientists. The problems here are the ones that come up repeatedly in system-plus-coding interviews at companies building AI infrastructure — not competitive programming, but the algorithmic reasoning that underlies real ML work.

Each solution is framed around the patterns an ML practitioner already uses: sliding windows in time-series preprocessing, graphs in DAG-based pipeline orchestration, dynamic programming in sequence modelling, LRU caches in feature stores. If you already think in ML, these problems will click faster than you expect.

Start Here

Five problems that cover the most common interview patterns, with ML system connections:

  • LRU Cache — HashMap + doubly-linked list. Shows up directly in feature stores and KV cache management.
  • Number of Islands — BFS/DFS on a grid. The pattern behind connected-component analysis in graph-based ML pipelines.
  • Course Schedule — Cycle detection in a DAG. Exactly how ML pipeline orchestrators validate dependency graphs.
  • Maximum Subarray — Kadane’s algorithm. The canonical dynamic programming pattern; appears in reward shaping and time-series problems.
  • Merge Intervals — Sorting + greedy. Used in audio segmentation, timeline deduplication, and scheduling systems.

Each problem includes:

  • Multiple approaches (brute force → optimal)
  • Time and space complexity analysis
  • Production engineering considerations
  • Connections to machine learning systems
  • Code examples and edge cases

Browse by Topic

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:


Problem Index

Below you’ll find all DSA problems in chronological order:


Content created with the assistance of large language models and reviewed for technical accuracy.

Two Sum

30 minute read

The hash table trick that makes O(n²) become O(n) and why this pattern appears everywhere from feature stores to embedding lookups.

Valid Parentheses

25 minute read

Why a simple stack solves bracket matching, expression parsing, and even neural network depth management in one elegant pattern.

Merge Two Sorted Lists

31 minute read

The pointer manipulation pattern that powers merge sort, data pipeline merging, and multi-source stream processing.

Best Time to Buy and Sell Stock

26 minute read

The single-pass pattern that powers streaming analytics, online algorithms, and real-time decision making in production systems.

Maximum Subarray (Kadane’s Algorithm)

25 minute read

Master the pattern behind online algorithms, streaming analytics, and dynamic programming, a single elegant idea powering countless production systems.

Climbing Stairs

26 minute read

The Fibonacci problem in disguise, teaching the fundamental transition from recursion to dynamic programming to space optimization.

Binary Tree Traversal

28 minute read

Master the fundamental patterns of tree traversal: the gateway to solving hundreds of tree problems in interviews.

Validate Binary Search Tree

25 minute read

Master BST validation to understand data integrity in tree structures, critical for indexing and search systems.

Binary Search

30 minute read

Master binary search to understand logarithmic algorithms and efficient searching, foundational for optimization and search systems.

Reverse Linked List

29 minute read

Master linked list manipulation through reversal - a fundamental pattern for understanding pointer logic and in-place algorithms.

LRU Cache

30 minute read

Master LRU cache design: O(1) get/put with hash map + doubly linked list. Critical for interviews and production caching systems.

Add Two Numbers

25 minute read

Master digit-by-digit addition with linked lists: Handle carry propagation elegantly. Classic problem teaching pointer manipulation and edge cases.

Container With Most Water

26 minute read

Master the two-pointer greedy technique that powers resource optimization in production ML systems.

Generate Parentheses

26 minute read

Master backtracking to generate all valid combinations, the foundation of ensemble model selection and multi-model systems.

Group Anagrams

26 minute read

Master hash-based grouping to solve anagrams, the foundation of clustering systems and speaker diarization in production ML.

Merge Intervals

23 minute read

Master interval processing to handle overlapping ranges, the foundation of event streams and temporal reasoning in production systems.

Add Two Numbers (Linked List)

15 minute read

Simulate arbitrary-precision addition on linked lists, the same sequential pattern used in large-scale distributed training and streaming pipelines.

Rotate Image

15 minute read

Master in-place matrix rotation, the same 2D transformation pattern that powers image and spectrogram augmentations in modern ML systems.

Spiral Matrix

15 minute read

Master systematic matrix traversal, the same pattern used for tracking experiments, processing logs, and managing state in ML systems.

Jump Game

26 minute read

Master greedy decision-making to determine reachability, the same adaptive strategy used in online learning and real-time speech systems.

Unique Paths

25 minute read

Master grid path counting with dynamic programming, the same optimization technique used in neural architecture search and speech model design.

Minimum Path Sum

23 minute read

The classic grid optimization problem that bridges the gap between simple recursion and 2D Dynamic Programming.

Decode Ways

17 minute read

A deceptive counting problem that teaches the fundamentals of state transitions and connects directly to Beam Search.

Word Break

22 minute read

The fundamental string segmentation problem that powers spell checkers, search engines, and tokenizers.

Word Ladder (BFS)

20 minute read

“Transforming ‘cold’ to ‘warm’ one letter at a time.”

Word Break

23 minute read

“Making sense of a stream of characters.”

Jump Game II

26 minute read

“Finding the optimal path through a sequence of choices.”

Binary Tree Maximum Path Sum

12 minute read

“Find the path to success, even if you have to start from the bottom, go up, and come back down.”

Word Search II

7 minute read

“Don’t look for one needle in a haystack. Magnetize the hay to find all needles at once.”

Alien Dictionary

7 minute read

“Language is just a graph of symbols. If you know the order, you know the language.”

Median of Two Sorted Arrays

24 minute read

“Stop thinking ‘merge’. Think ‘partition’, the median is just the boundary between two halves.”

Trapping Rain Water

23 minute read

“Water doesn’t care about every bar, only the highest walls to the left and right.”

First Missing Positive

22 minute read

“The missing number is hiding in plain sight, use the array itself as the hash table.”

Wildcard Matching

22 minute read

“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 to...

N-Queens

19 minute read

“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

20 minute read

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

Largest Rectangle in Histogram

7 minute read

“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

7 minute read

“Regular Expression Matching is where string manipulation meets automata theory. It requires translating a sequence of patterns into a resilient state machin...

Sudoku Solver

9 minute read

“Sudoku Solver is the quintessential backtracking problem, it represents the transition from simple recursion to a multi-constraint search problem where ever...

LFU Cache (Least Frequently Used)

19 minute read

“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(...