DSA · Problems
LeetCode-style problems
Hand-picked problems with the insight first, then the code. No 50-line solution before you've understood why.
- EasyLC #14m
Two Sum
Find two indices whose values sum to a target. The classic O(n) hashmap warm-up.
arrayshashmap - MediumLC #36m
Longest Substring Without Repeating Characters
Sliding window with a 'last seen' index — O(n), single pass.
stringssliding-windowhashmap - MediumLC #116m
Container With Most Water
Maximize trapped area between two vertical lines — two pointers from each end.
arraystwo-pointers - MediumLC #157m
3Sum
Find all unique triplets summing to zero. Sort + two-pointers, with deduping.
arraystwo-pointerssorting - HardLC #428m
Trapping Rain Water
How much water can a 1D elevation map hold? Two-pointer solution in O(n) without prefix arrays.
arraystwo-pointersmonotonic - MediumLC #565m
Merge Intervals
Sort by start, then sweep — merging overlapping intervals in O(n log n).
arrayssortingintervals - EasyLC #1214m
Best Time to Buy and Sell Stock
Maximize profit with one buy and one sell. Track the minimum so far in a single pass.
arraysgreedy - MediumLC #1397m
Word Break
Can a string be segmented into dictionary words? 1D DP with O(n²) substring checks (or trie).
dpstringshashset - MediumLC #1468m
LRU Cache
O(1) get/put with a HashMap + doubly-linked list. The textbook design problem.
designlinked-listhashmap - MediumLC #2006m
Number of Islands
Count connected components of '1's in a grid. BFS/DFS or Union-Find — both O(m·n).
graphbfsdfs - MediumLC #2076m
Course Schedule
Cycle detection in a directed graph via Kahn's algorithm — the canonical topological sort problem.
graphtopological-sortbfs - MediumLC #2385m
Product of Array Except Self
Compute prefix products and suffix products in two passes — O(n), no division.
arraysprefix-suffix - MediumLC #3226m
Coin Change
Minimum number of coins to make a target amount. Bottom-up DP, O(amount × |coins|).
dp