Skip to content

NeetCode Practice Framework

GitHub stars Python 3.11 License: MIT

Solve. Forget. Repeat. Let's fix that.

"Algorithm mastery is not about memorizing 300 solutions β€” it's about internalizing 15 fundamental patterns."


See the Big Picture

AI Mind Map

Our AI-generated mind maps reveal how patterns connect β€” relationships that take years to internalize on your own.

Mind Map Preview

English Β· 繁體中文 Β· All Mind Maps β†’


What Makes This Different

1. Pattern Learning with Two Paths

Each pattern comes with two complementary guides:

  • πŸ’‘ Intuition β€” Understand the why through stories and visual metaphors
  • πŸ› οΈ Templates β€” Production-ready code for interviews and quick reference

Example from Sliding Window:

"The window is a moving lens of attention β€” it forgets the past to focus on what matters now."

Every sliding window algorithm is a dance between two forces: The Explorer (right pointer) discovers new territory, while The Gatekeeper (left pointer) enforces validity.

This isn't just another solution collection. It's a system for building transferable intuition.

2. Production-Grade Testing

Your solution passes LeetCode. But is it correct? Is it optimal?

Compare multiple approaches:

python runner/test_runner.py 0215_kth_largest --all --benchmark
╔════════════════════════════════════════════════════╗
β•‘ 0215_kth_largest_element_in_an_array - Performance β•‘
╠════════════════════════════════════════════════════╣
β•‘ default:     β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  114ms           β•‘
β•‘ quickselect: β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘   96ms           β•‘
β•‘ heap:        β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘  107ms           β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

Method         Avg Time   Pass Rate  Complexity
-----------  ----------  ----------  --------------------
default        113.51ms         3/3  O(n) average time, O(1) space
quickselect     96.06ms         3/3  O(n) average time, O(1) space
heap           107.34ms         3/3  O(n log k) time, O(k) space

Why algorithm choice matters β€” real data from 100+ problems:

Benchmark Results (n = 5,000)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Problem               β”‚ Fast                   β”‚ Slow                   β”‚ Speedup   β”‚ Time Complexity     β”‚ Space Complexity     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0010 Regex Matching   β”‚ Top-down Memo 0.08ms   β”‚ Bottom-up DP 5.3s      β”‚ 62,000Γ—   β”‚ O(mn) vs O(mn)      β”‚ O(mn) vs O(mn)       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0044 Wildcard Match   β”‚ Greedy Backtrack 1.4ms β”‚ 2D DP Table 10.0s      β”‚ 7,000Γ—    β”‚ O(mn) vs O(mn)      β”‚ O(1) vs O(mn)        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0011 Container Water  β”‚ Two Pointers 0.75ms    β”‚ Nested Loops 4.9s      β”‚ 7,000Γ—    β”‚ O(n) vs O(nΒ²)       β”‚ O(1) vs O(1)         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0121 Buy Sell Stock   β”‚ Running Min 2.0ms      β”‚ Nested Loops 3.1s      β”‚ 2,000Γ—    β”‚ O(n) vs O(nΒ²)       β”‚ O(1) vs O(1)         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0416 Partition Sum    β”‚ 2D DP Table 0.08ms     β”‚ 1D DP Space-Opt 96.6ms β”‚ 1,000Γ—    β”‚ O(nΓ—target) vs same β”‚ O(nΓ—target) vs O(t)  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0016 3Sum Closest     β”‚ Two Ptr+Prune 1.1ms    β”‚ Two Ptr Basic 1.4s     β”‚ 1,000Γ—    β”‚ O(nΒ²) vs O(nΒ²)      β”‚ O(1) vs O(1)         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0435 Non-Overlap Intv β”‚ Greedy Sort 5.0ms      β”‚ DP Array 3.1s          β”‚ 617Γ—      β”‚ O(n log n) vs O(nΒ²) β”‚ O(1) vs O(n)         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0001 Two Sum          β”‚ Hash Map 0.66ms        β”‚ Nested Loops 70.1ms    β”‚ 106Γ—      β”‚ O(n) vs O(nΒ²)       β”‚ O(n) vs O(1)         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0494 Target Sum       β”‚ DP Transform 0.04ms    β”‚ Memoization 3.2ms      β”‚ 73Γ—       β”‚ O(nΓ—sum) vs same    β”‚ O(sum) vs O(nΓ—sum)   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0875 Koko Bananas     β”‚ Binary Search 14.6ms   β”‚ Linear Search 1.1s     β”‚ 72Γ—       β”‚ O(n log m) vs O(nm) β”‚ O(1) vs O(1)         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“Š Full benchmark: 100+ problems, 300+ solutions β†’

Try it yourself:

python runner/test_runner.py 0011_container --all --estimate

Auto-save failing cases for debugging:

gen_3: ❌ FAIL [generated]
   β”Œβ”€ Input ─────────────────────────────────
   β”‚ [1,3,5,7]
   β”‚ [2,4,6,8]
   β”œβ”€ Actual ────────────────────────────────
   β”‚ 4.5
   └─────────────────────────────────────────
   πŸ’Ύ Saved to: tests/0004_failed_1.in

More capabilities: - Seeded random generation for reproducible stress testing - Custom judge functions for multiple valid answers - Memory profiling with sparkline visualization

3. AI-Powered Knowledge Graph

We built an interconnected ontology: API Kernels β†’ Patterns β†’ Problem Families.

AI analyzes this structure to generate insights humans miss β€” synthesizing perspectives from Architect, Professor, Engineer, and Competitor viewpoints.


Quick Start

1. Setup

# Clone and setup
git clone https://github.com/lufftw/neetcode.git
cd neetcode

# Create virtual environment (Python 3.11)
python -m venv leetcode
leetcode\Scripts\activate  # Windows
source leetcode/bin/activate  # Linux/macOS

# Install dependencies
pip install -r requirements.txt

2. Create a Problem

scripts\new_problem.bat 1 --with-tests  # Windows
./scripts/new_problem.sh 1 --with-tests  # Linux/macOS

3. Run Tests

python runner/test_runner.py 0001_two_sum

That's it. Press F5 in VS Code to debug, or Ctrl+Shift+B to run all tests.


Pattern Guides

Each pattern provides Intuition + Templates. Start with intuition, use templates for interviews.

Pattern Intuition Templates Example Problems
Sliding Window πŸ’‘ πŸ› οΈ LC 3, 76, 209, 239, 340, 438, 567
Two Pointers πŸ’‘ πŸ› οΈ LC 11, 15, 16, 26, 27, 75, 80, 88, 125, 141, 142, 167, 202, 283, 287, 876, 977
Binary Search πŸ’‘ πŸ› οΈ LC 4, 33, 34, 35, 81, 162, 875, 1011
Backtracking πŸ’‘ πŸ› οΈ LC 39, 40, 46, 47, 51, 52, 77, 78, 79, 90, 93, 131, 216
Monotonic Stack πŸ’‘ πŸ› οΈ LC 42, 84, 85, 316, 402, 496, 503, 739, 901, 907
Dynamic Programming πŸ’‘ πŸ› οΈ LC 70, 72, 121, 198, 213, 322, 416, 494, 516, 518, 746
Graph Traversal πŸ’‘ πŸ› οΈ LC 133, 200, 207, 210, 286, 417, 542, 547, 743, 785, 787, 802, 841, 994, 1631
Tree Traversal πŸ’‘ πŸ› οΈ LC 94, 102, 104, 110, 124, 337, 543, 968

View All 25+ Patterns β†’


Features at a Glance

Category Capabilities
Testing Random generation, custom judges, stress testing, complexity estimation
Learning Pattern intuition guides, reusable templates, dual-path documentation
Visualization AI mind maps, pattern hierarchy, problem relationships
Tooling VS Code integration, one-command scaffolding, benchmarking

Documentation

Getting Started

Document Description
Create New Problem How to scaffold a new problem
Solution Contract Solution file format and requirements
Test File Format How to write .in/.out test files

Learning

Document Description
Pattern Guides All 25+ patterns with Intuition + Templates
Test Runner Testing, benchmarking, and validation
Benchmarks 100+ problems compared: speedups up to 65,000x

Advanced

Document Description
Generator Contract Random test generation for stress testing

Contributing

We welcome contributions! See our Contributor Guide.

# Run unit tests
python -m pytest .dev/tests -v

License

MIT License β€” Free for personal learning and educational use.


Built for learners who want to understand, not just memorize.

πŸ“š Docs Β· 🧠 Mind Maps Β· πŸ“ Patterns Β· πŸ§ͺ Testing