Skip to content

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

signal      = "minimum steps"
edge_weight = 1

model       = graph(states, moves)
algorithm   = BFS
invariant   = "queue order is nondecreasing distance"

prove()
implement()
test_boundaries()

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

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.