Turn problem signals into working code¶
DSA Atlas is an open handbook for the gap between recognizing an algorithm and implementing it correctly under interview constraints.
Read the prompt as a set of operations. Bound those operations with the input constraints. Choose a data structure that makes the repeated operation cheap. Then write the invariant before the loop.
Start with the solve loop Browse tested code Explore System Design Atlas
A tested code pattern¶
When a prompt asks for two distinct values that reach a target, the brute-force pair scan repeats the same complement search. A hash map turns that repeated search into expected constant time while preserving the earlier index.
def two_sum(values: Sequence[int], target: int) -> tuple[int, int] | None:
"""Return indices of two distinct values whose sum is ``target``."""
position: dict[int, int] = {}
for index, value in enumerate(values):
complement = target - value
# Search before insertion so an element cannot match itself.
if complement in position:
return position[complement], index
# Remember this index for complements that appear later.
position[value] = index
return None
inline std::vector<int> two_sum(
const std::vector<int>& values, int target) {
std::unordered_map<long long, int> position;
for (int index = 0; index < static_cast<int>(values.size()); ++index) {
const long long complement =
static_cast<long long>(target) - static_cast<long long>(values[index]);
const auto found = position.find(complement);
// Search before insertion so an element cannot match itself.
if (found != position.end()) {
return std::vector<int>{found->second, index};
}
// Remember this index for complements that appear later.
position[static_cast<long long>(values[index])] = index;
}
return std::vector<int>();
}
inline std::vector<int> two_sum(
const std::vector<int>& values, int target) {
std::unordered_map<long long, int> position;
for (int index = 0; index < static_cast<int>(values.size()); ++index) {
const long long complement =
static_cast<long long>(target) - static_cast<long long>(values[index]);
const auto found = position.find(complement);
// Search before insertion so an element cannot match itself.
if (found != position.end()) {
return std::vector<int>{found->second, index};
}
// Remember this index for complements that appear later.
position[static_cast<long long>(values[index])] = index;
}
return std::vector<int>();
}
Every sample shown in the learning chapters comes from the source tree and is exercised by the repository's behavior tests.
The learning path¶
00 · Start Use this book Move between explanation, source, tests, and deliberate practice.
01 · Method Solve before coding A repeatable loop from constraints to invariant.
02 · Bounds Complexity and constraints Turn input limits into an algorithm budget.
03 · Sequences Arrays and hashing Turn repeated scans into constant-time memory.
04 · Order Stacks, queues, and windows Maintain only the candidates that can still matter.
05 · Hierarchy Trees and heaps Write subtree contracts and manage the next extreme candidate.
06 · Relationships Graphs Model states and choose traversal by edge meaning.
07 · Boundaries Search and sort Make the search contract explicit before moving either bound.
08 · Choices Backtracking Explore, undo, and prune without losing the path invariant.
09 · State Dynamic programming Define the state before writing the recurrence.
10 · Advanced Structure and flow Shortest paths, connectivity, and capacity.
11 · Design Composite structures Assign each required operation to the structure that owns it.
12 · Toolkit Interview primitives Linked lists, greedy proofs, bit state, and string matching.
13 · Indexes Advanced trees Balanced order, prefixes, mutable ranges, and spatial search.
Appendix Quick reference Signals, invariants, and complexity at a glance.
Practice Problem catalog Map recognition signals to patterns and first questions.
What makes this book different¶
- Chapters explain decisions. Templates are grouped by the reasoning that selects them, not just by data-structure name.
- Code is real source. C++11 and C++17 compile from the same templates, and Python imports; all are exercised by behavior tests.
- Invariants come first. Every core pattern states what must remain true as its loop or recursion advances.
- The repository is the book. Fixes to explanations, code, and tests travel together through review and deployment.
Scope
This is a focused interview handbook, not an encyclopedia. Advanced algorithms enter the copy-ready library only after they receive executable tests.