I built this because I wanted a simple way to practise algorithms without keeping a browser, an editor, and an online judge open at the same time.
The repository contains 150 interview problems in the hot_150/ directory.
Every question is an ACM-style program: its Python file reads from stdin, writes to
stdout, and the judge compares the output exactly (whitespace-normalised). This
mirrors a real online assessment environment, so the usual loop stays on your
machine:
pick a problem -> write its question file -> run it -> inspect the failing case
It also keeps a small SQLite progress file locally. Your attempts and completed solutions are ignored by Git and are not part of this public repository.
If you are learning a pattern for the first time rather than reviewing it, start with the learning protocol. It defines the function-to-ACM transfer, hint ladder, daily session, and mastery criteria. All NeetCode problem links are collected in the central problem index.
Python 3.12 or newer is required. There are no third-party Python dependencies.
git clone https://github.com/pllsparrow/offline-algorithm-trainer.git
cd offline-algorithm-trainer
python3 train.py list
python3 train.py show two-sum
python3 train.py run two-sum
python3 train.py run 003
python3 train.py statusInstall the web dependencies once, then start the local-only service:
python3 -m venv .venv
.venv/bin/python -m pip install -r requirements-web.txt
.venv/bin/python web_debug_server.pySet ALGORITHM_TRAINER_PYTHON when the service should use a specific Python
3.12 interpreter for submitted programs.
The API uses FastAPI and exposes local documentation at /api/docs. The editor
is a locally bundled CodeMirror 6 build with Python highlighting, four-space
indentation, visible spaces, and breakpoint gutters. Run npm install && npm run build:web only when changing web/editor.js.
Then open http://127.0.0.1:8765. The browser app provides problem navigation,
SQLite drafts, curated examples, custom runs, full submissions, breakpoints,
continue, step over, locals, and a compact call stack. A submission runs the
problem's complete fixed case set and writes the source back to hot_150/ after
the run finishes.
Open the qNNN_problem_name.py path printed by show. The file contains only
short Input and Output comments, so write the input parsing, algorithm,
output, and program entry point yourself. Then run the same problem again. A
failed case prints its stdin, expected stdout, and actual stdout.
For a stubborn failure, rerun only that case:
python3 train.py run two-sum --case 1You can also filter the list:
python3 train.py list --category graph
python3 train.py list --difficulty HardAll 150 problems use a pure text protocol. Each test case has a stdin payload and an expected stdout payload. The judge runs your file as an independent Python process, feeds it the stdin, captures stdout, and compares it (whitespace-normalised) against the expected output.
Each of 148 problems has 50 distinct cases covering boundaries, duplicates,
extreme values, sizes, and structural shapes. generate-parentheses and
n-queens use 9 and 10 exhaustive/boundary inputs instead; their valid input
domains are too small to justify padding the corpus with duplicates.
Common input formats:
- Integer list: count
non one line, thennintegers on the next. - Single integer / float / string token: one line.
- Whole line string (may contain spaces): one line, read with
readline. - Integer matrix:
r con the first line, thenrlines ofcintegers. - Character board:
r con the first line, thenrlines ofcchars. - Binary tree: count
n, thennlevel-order values (nullfor missing). - Graph adjacency: count
n, then per node degreedanddneighbour ids. - Linked list: count
n, thennintegers. - Operations (design problems): first line
q(operation count), thenqlines ofop args.... Output one result per operation (nullfor void).
For problems with multiple valid answers (e.g. group-anagrams, 3sum,
subsets), the expected output is canonicalised (sorted), so you must print in
the same sorted order to pass.
Inspect a problem's exact format before solving it:
python3 train.py show two-sum
python3 train.py checkscripts/build_acm.py deterministically regenerates all 150 specs from
data/problems.json and data/tests.json.
| Command | What it does |
|---|---|
python3 train.py list |
Lists problems and local progress |
python3 train.py show <slug> |
Shows the problem details, ACM format, and file path |
python3 train.py run <slug> |
Runs the local ACM test cases |
python3 train.py run <number> |
Runs by problem number, for example run 001 |
python3 train.py run <slug> --case 1 |
Repeats one failing case |
python3 train.py run <slug> --all |
Runs the remaining cases after a failure |
python3 train.py status |
Shows attempted and accepted totals |
python3 train.py check |
Checks the repository data |
python3 train.py scaffold --force |
Resets all question files to their I/O comments |
PyCharm users can select the shared Judge Current Solution run configuration once. After that, open any file in hot_150/ and use the green Run button to judge the current file.
All 150 Python files are stored directly under hot_150/ and named like
q001_contains_duplicate.py. The judge is in judge/, while problem metadata,
tests, and your local progress live under data/.
Heap and bucket follow-up exercises live in
muscle_memory/heapq&buckets/. This set
contains fifteen interview-focused variants with 99 deterministic cases each and
semantic validators for problems that allow tied answers.
Recursion drills live in
muscle_memory/recursion/. The twenty
exercises cover recursion fundamentals, search, divide and conquer, and tree
recursion. Ten are tree-focused, with 49 deterministic cases per exercise.
Problem names and links refer to exercises on LeetCode and NeetCode. This repository contains my own summaries, hints, starter templates, test harness, and local test data. It does not republish full commercial problem statements or official solutions. See NOTICE.md for details.
The original code in this repository is released under the MIT License.