Skip to content

πŸ”§ NeetCode Tools

Status: Informational
Scope: All developer tools in tools/ directory
Last Updated: December 31, 2025 19:22:24
Created: December 10, 2025 10:15:57

Developer tools for checking, validating, and generating project content.


πŸ“‹ Quick Reference

Category Tool Purpose
Checking check_solutions.py Validate solution file architecture compliance
run_format_tests.py Run format unit tests
check_test_files.py Check and fix test files with double newline endings
Review fix_docstring.py Auto-fix file-level docstrings from LeetCode
Data leetcode-api SQLite-backed cache for LeetCode question data
Generation generate_mindmaps.py Rule-based mind map generation
generate_mindmaps_ai.py AI-powered mind map generation
generate_pattern_docs.py Pattern documentation generation
html_meta_description_generator.py Generate SEO meta descriptions from Markdown
Automation Pre-commit Hooks Auto-generate AI mind maps on commit
Utilities text_to_mindmap.py Convert text to mind map format
prepare_llm_input.py Prepare LLM input data

πŸš€ Quick Start

# Check all solution files
python tools/review-code/validation/check_solutions.py

# Generate mind maps (rule-based)
python tools/mindmaps/generate_mindmaps.py --html

# Generate mind maps (AI)
python tools/mindmaps/generate_mindmaps_ai.py --goal interview

# Generate pattern documentation
python tools/patterndocs/generate_pattern_docs.py

# Generate SEO meta descriptions
python tools/mindmaps/html_meta_description_generator.py

πŸ“ Directory Structure

tools/
β”œβ”€β”€ README.md                      # Tools overview
β”œβ”€β”€ reorganization-plan.md         # Reorganization plan and migration details
β”‚
β”œβ”€β”€ mindmaps/                      # πŸ—ΊοΈ Mind map generation (consolidated)
β”‚   β”œβ”€β”€ core/                      # Core module
β”‚   β”‚   β”œβ”€β”€ generators/            # Mind map type generators
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ ai-markmap-agent/          # AI markmap agent
β”‚   β”œβ”€β”€ ai_mindmap/                # AI mindmap module
β”‚   β”œβ”€β”€ hooks/                     # Git hooks for mindmaps
β”‚   β”œβ”€β”€ prompts/                   # AI prompts
β”‚   β”œβ”€β”€ shared/                    # Shared utilities
β”‚   β”œβ”€β”€ tests/                     # Mindmap tests
β”‚   β”œβ”€β”€ generate_mindmaps.py       # Rule-based generator
β”‚   β”œβ”€β”€ generate_mindmaps_ai.py    # AI generator
β”‚   β”œβ”€β”€ sync_mindmap_html.py       # HTML sync tool
β”‚   └── html_meta_description_generator.py  # SEO meta generator
β”‚
β”œβ”€β”€ patterndocs/                   # πŸ“š Pattern documentation generation
β”‚   β”œβ”€β”€ generate_pattern_docs.py   # Pattern docs generator
β”‚   └── ...
β”‚
β”œβ”€β”€ review-code/                   # πŸ” Code review tools
β”‚   β”œβ”€β”€ fix_docstring.py           # Auto-fix docstrings
β”‚   └── validation/                # Validation tools
β”‚       β”œβ”€β”€ check_solutions.py     # Solution checker
β”‚       β”œβ”€β”€ check_test_files.py    # Test file checker
β”‚       β”œβ”€β”€ run_format_tests.py    # Format test runner
β”‚       └── tests/                 # Validation tests
β”‚
β”œβ”€β”€ docstring/                     # πŸ“ Docstring utilities
β”‚   β”œβ”€β”€ formatter.py               # Docstring formatting logic
β”‚   └── README.md
β”‚
β”œβ”€β”€ leetcode-api/                  # πŸ”— LeetCode data cache
β”‚   β”œβ”€β”€ question_api.py            # Unified public API
β”‚   β”œβ”€β”€ question_store.py          # SQLite storage layer
β”‚   └── data/                      # LeetScrape data files
β”‚
β”œβ”€β”€ maintenance/                   # πŸ”§ Maintenance tools
β”‚   └── doc-naming/                # Document naming tools
β”‚
└── _staging/                      # πŸ“¦ Staging area (to be organized)
    β”œβ”€β”€ prepare_llm_input.py
    └── ...

πŸ” Checking Tools

check_solutions.py

Checks all solution files for Pure Polymorphic Architecture compliance.

python tools/review-code/validation/check_solutions.py              # Standard check
python tools/review-code/validation/check_solutions.py --verbose    # Show fix suggestions
python tools/review-code/validation/check_solutions.py --list-warnings  # List only files with warnings
python tools/review-code/validation/check_solutions.py --show-warnings  # Show warnings with suggestions

Checks Performed:

Category What It Checks
Architecture SOLUTIONS dictionary exists with class field
No wrapper functions (solve_*)
solve() uses get_solver()
Correct import: from _runner import get_solver
Format Comments use Solution 1: format
Comments placed BEFORE class definition
Complexity Each solution has # Time: O(...)
Each solution has # Space: O(...)

Example Output:

============================================================
πŸ“Š Solution Format Check Summary
============================================================
Total files: 34
βœ… OK: 30
⚠️ Warnings: 2
❌ Errors: 2
============================================================

run_format_tests.py

Runs unit tests for format checking.

python tools/review-code/validation/run_format_tests.py           # Standard run
python tools/review-code/validation/run_format_tests.py --verbose # Verbose output
python tools/review-code/validation/run_format_tests.py --quiet   # Quiet mode

run_format_tests.bat / run_format_tests.sh

Runs complete format check (checker + unit tests).

tools\review-code\validation\run_format_tests.bat     # Windows
tools/review-code/validation/run_format_tests.sh      # Linux/Mac

check_test_files.py

Check and fix double newline ending errors in test files under tests/ directory.

Checks all .in and .out files to find files ending with two newlines (\n\n).

python tools/review-code/validation/check_test_files.py              # List problematic files
python tools/review-code/validation/check_test_files.py --fix        # List and auto-fix
python tools/review-code/validation/check_test_files.py --verbose    # Show detailed info

Features: - List all test files ending with two newlines - Auto-fix: Remove extra newline, keep only one

Example Output:

Found 3 files ending with two newlines:

  tests/0977_squares_of_a_sorted_array_1.in
  tests/0977_squares_of_a_sorted_array_1.out
  tests/0142_linked_list_cycle_ii_1.in

Tip: Use --fix to automatically fix these issues.


πŸ“ Code Review Tools

fix_docstring.py

Auto-fix file-level docstrings for solution files by fetching data from LeetCode.

Located in: tools/review-code/fix_docstring.py

# Fix files in range (e.g., 0077-0142)
python tools/review-code/fix_docstring.py --range 77 142

# Fix single file (e.g., 0202)
python tools/review-code/fix_docstring.py --range 202 202

# Custom delay to avoid rate limiting
python tools/review-code/fix_docstring.py --range 77 142 --delay-min 3.0 --delay-max 8.0

python tools/review-code/fix_docstring.py --range 209 1000 --delay-min 60.0 --delay-max 120.0

python tools/review-code/fix_docstring.py --range 1 1000 --delay-min 30.0 --delay-max 66.0

Parameters:

Parameter Default Description
--range START END Required Problem number range to process
--delay-min 3.0 Minimum delay between requests (seconds)
--delay-max 8.0 Maximum delay between requests (seconds)

What It Does:

  1. Reads problem info from local cache (tools/leetcode-api/crawler/.cache/leetcode_problems.json)
  2. Fetches description and constraints from LeetCode via leetscrape
  3. Generates docstring following review-code README format
  4. Updates the solution file

Example Output:

Processing 0202 ~ 0202
Delay: 3.0s ~ 8.0s

  Fetching happy-number... (1 constraints)
[OK] 0202_happy_number.py: Updated

==================================================
Summary: Fixed 1 files
==================================================

Dependencies: - leetscrape library for fetching LeetCode data - Local cache file with problem metadata


🧠 Mind Map Generation

generate_mindmaps.py

Rule-based mind map generator that creates 9 types of mind maps from ontology data.

python tools/mindmaps/generate_mindmaps.py          # Generate Markdown
python tools/mindmaps/generate_mindmaps.py --html   # Generate HTML (interactive)

Configuration: tools/mindmaps/generate_mindmaps.toml

Generation Types:

Type Description
pattern_hierarchy API Kernel β†’ Pattern β†’ Problem
family_derivation Base template β†’ Derived variants
algorithm_usage Algorithm β†’ Problems
data_structure Data structure β†’ Problems
company_coverage Company β†’ Problems
roadmap_paths Learning roadmaps
problem_relations Related problems network
solution_variants Multiple solution approaches
difficulty_topics Difficulty Γ— Topics matrix

πŸ“– Detailed technical docs: mindmaps/README.md

generate_mindmaps_ai.py

AI-powered mind map generator using LLM for creative generation.

# Interactive mode
python tools/mindmaps/generate_mindmaps_ai.py

# Specific goals
python tools/mindmaps/generate_mindmaps_ai.py --goal interview        # Interview prep
python tools/mindmaps/generate_mindmaps_ai.py --goal systematic       # Systematic learning
python tools/mindmaps/generate_mindmaps_ai.py --goal pattern_mastery  # Pattern mastery

# Specific topics
python tools/mindmaps/generate_mindmaps_ai.py --topic sliding_window
python tools/mindmaps/generate_mindmaps_ai.py --topic dynamic_programming

# Generate HTML only (from existing Markdown files)
python tools/mindmaps/generate_mindmaps_ai.py --html-only            # Skip Markdown generation, only update HTML

HTML-Only Mode (--html-only):

The --html-only flag allows you to generate HTML files from existing Markdown mind map files without regenerating the Markdown content. This is useful when:

  • You've updated meta description files and want to refresh HTML output
  • You want to regenerate HTML with updated meta descriptions
  • You've manually edited Markdown files and want to update HTML without running the full AI generation

The command reads existing Markdown files from the configured output directory and generates corresponding HTML files with proper meta descriptions. It automatically:

  • Detects language-specific Markdown files (e.g., neetcode_ontology_ai_en.md, neetcode_ontology_ai_zh-TW.md)
  • Loads corresponding meta description files (auto-detects from tools/mindmaps/core/meta/)
  • Generates HTML with proper <meta name="description"> tags
  • Preserves all Markdown content in the HTML output

Configuration: tools/mindmaps/generate_mindmaps_ai.toml

Section What You Can Configure
[model] LLM model, temperature, max tokens
[output] Output directory, filename, HTML generation
[ontology] Which knowledge graph data to include
[problems] Problem filters (difficulty, topics, roadmaps)
[links] GitHub repo URL, branch
[advanced] Output language(s) (multi-language support)

No API Key? After running, copy tools/mindmaps/prompts/generated/mindmap-prompt.md to ChatGPT/Claude.

πŸ“– Detailed usage guide: prompts/README.md


πŸ“ Pattern Documentation Generation

generate_pattern_docs.py

Composes pattern documentation from source files in meta/patterns/.

# Generate all pattern docs
python tools/patterndocs/generate_pattern_docs.py

# Generate specific pattern
python tools/patterndocs/generate_pattern_docs.py --pattern sliding_window

Configuration: tools/patterndocs/generate_pattern_docs.toml

Source Structure:

meta/patterns/sliding_window/
β”œβ”€β”€ _config.toml        # File ordering (optional)
β”œβ”€β”€ _header.md          # Introduction and core concepts
β”œβ”€β”€ 0003-base.md        # Base template problem
β”œβ”€β”€ 0076_variant.md     # Variant problem
β”œβ”€β”€ _comparison.md      # Pattern comparison table
β”œβ”€β”€ _decision.md        # Decision guide
└── _templates.md       # Template code

πŸ“– Detailed technical docs: patterndocs/README.md

html_meta_description_generator.py

Generates SEO-friendly HTML meta descriptions from Markdown files using OpenAI GPT-4o. Follows the Meta Description Generation Spec for optimal search engine result page (SERP) display.

# Generate descriptions for all configured files
python tools/mindmaps/html_meta_description_generator.py

# Generate description for a specific file
python tools/mindmaps/html_meta_description_generator.py --file docs/mindmaps/pattern-hierarchy.md

# List configured files
python tools/mindmaps/html_meta_description_generator.py --list

# Specify output directory
python tools/mindmaps/html_meta_description_generator.py --output custom/output/dir

# Force overwrite existing files
python tools/mindmaps/html_meta_description_generator.py --force

Configuration: tools/mindmaps/html_meta_description_generator.toml

Features: - Automatic markdown cleaning (removes code blocks, images, links, etc.) - Language detection (English/Chinese Traditional) - Length validation (80-160 characters, truncates at sentence boundaries) - Content validation (removes boilerplate, keyword stuffing, etc.) - HTML attribute escaping - OpenAI GPT-4o integration for high-quality descriptions

Configuration Options:

Setting Description Default
minLen Minimum description length 80
maxLen Maximum description length 160
preferFrontmatterDescription Use frontmatter description if available true
keepInlineCodeContent Keep inline code text (remove backticks) true
keepImageAlt Keep image alt text true
languageMode Language mode: "auto", "en", "zh-TW" "auto"
outputDir Output directory for generated files "tools/mindmaps/core/meta"

Prompt Templates:

The tool uses configurable prompt templates in the [prompts] section: - system - System prompt for OpenAI - user - User prompt template with placeholders: {title}, {content_preview}, {candidate_info}, {language}

API Key:

The OpenAI API key is prompted interactively when running the program (input is hidden for security). No need to set environment variables.

Example Configuration:

[files]
"docs/mindmaps/pattern-hierarchy.md" = { }
"docs/mindmaps/family-derivation.md" = { minLen = 100, maxLen = 155 }

πŸ› οΈ Utility Tools

text_to_mindmap.py

Converts plain text to Markmap mind map format.

python tools/mindmaps/text_to_mindmap.py input.txt -o output.md

prepare_llm_input.py

Prepares LLM input data by integrating ontology and problem information.

python tools/_staging/prepare_llm_input.py --output llm_input.json

Use Cases: - Prepare input data for AI analysis - Export problem and pattern information - Generate context for prompts


πŸ§ͺ Testing

Format Tests

# Run format tests
pytest tools/review-code/validation/tests/test_solution_format.py -v

# Or use standalone script
python tools/review-code/validation/run_format_tests.py

Generator Tests

# Mind map generation tests
pytest .dev/tests/test_generate_mindmaps.py -v

# Pattern docs generation tests
pytest .dev/tests/test_generate_pattern_docs.py -v

πŸ“Š Test Architecture Overview

neetcode/
β”œβ”€β”€ tools/review-code/validation/tests/  # Format compliance tests
β”‚   └── test_solution_format.py
β”‚
β”œβ”€β”€ tools/mindmaps/tests/                # Mind map tests
β”‚   └── test_post_processing.py
β”‚
β”œβ”€β”€ .dev/tests/                          # Component tests (runner modules)
β”‚   β”œβ”€β”€ test_generate_mindmaps.py
β”‚   β”œβ”€β”€ test_generate_pattern_docs.py
β”‚   └── ...
β”‚
└── .dev/tests_solutions/                # Solution correctness tests
    └── test_all_solutions.py

Run All Tests:

.dev\run_all_tests.bat    # Windows
.dev/run_all_tests.sh     # Linux/Mac

πŸ”„ Local CI/CD Automation

Pre-commit Hooks

The project uses pre-commit framework to automatically generate AI mind maps when relevant files are modified.

Setup

# Install pre-commit (if not already installed)
pip install pre-commit

# Install Git hooks
pre-commit install

How It Works

When you commit changes to: - ontology/ directory - meta/problems/ directory
- tools/mindmaps/generate_mindmaps.py

The hook automatically runs tools/mindmaps/generate_mindmaps_ai.py to generate AI-powered mind maps.

Usage

Normal workflow (automatic):

# Modify relevant files and commit
git add ontology/some_file.json
git commit -m "Update ontology"
# Hook automatically runs, prompts for API key, generates mind maps

Skip AI generation:

# Method 1: Use commit message tag
git commit -m "Update ontology [skip-ai]"

# Method 2: Use environment variable
# PowerShell
$env:SKIP_AI_MINDMAPS = "true"
git commit -m "Update ontology"

# CMD
set SKIP_AI_MINDMAPS=true
git commit -m "Update ontology"

# Method 3: Skip all hooks
git commit --no-verify -m "Update ontology"

Manual testing:

# Test all hooks
pre-commit run --all-files

# Test specific hook
pre-commit run generate-ai-mindmaps --all-files

Configuration

  • Config file: .pre-commit-config.yaml
  • Hook script: tools/mindmaps/hooks/generate_ai_mindmaps_hook.py
  • API Key: Interactive input (not stored in any file)
  • Branch support: Works on all branches

Features

Feature Description
Auto-detection Detects changes in ontology/, meta/problems/, tools/mindmaps/generate_mindmaps.py
API Key Interactive input, never stored
Skip options Multiple ways to skip when needed
Branch support Works on all branches
Docker Act compatible Doesn't interfere with local GitHub Actions testing

Document Description
solution-contract.md Solution file specification
generator-contract.md Generator file specification
architecture-migration.md Architecture migration guide
mindmaps/README.md Mind map module technical docs
patterndocs/README.md Pattern docs module technical docs
mindmaps/ai-markmap-agent/README.md AI Markmap Agent docs
prompts/README.md AI prompts usage guide

❓ FAQ

check_solutions.py reports errors - how to fix? **Missing Solution Comment:**
# Add before class definition:
# ============================================
# Solution 1: Hash Map
# Time: O(n), Space: O(n)
# ============================================
class Solution:
    ...
**Wrong Comment Format:**
# Change "Solution:" to "Solution 1:"
# Solution 1: Two Pointers  βœ…
# Solution: Two Pointers    ❌
How to add a new mind map type? 1. Create new file in `tools/mindmaps/core/generators/` 2. Implement generator function 3. Register in `generators/__init__.py` 4. Add tests to `.dev/tests/test_generate_mindmaps.py` See [mindmaps/README.md](mindmaps/README.md#adding-a-new-generator)
How to add new pattern documentation? 1. Create directory `meta/patterns//` 2. Add `_header.md` (required) 3. Add problem files (e.g., `0003_base.md`) 4. Optionally add `_config.toml` to control order 5. Run `python tools/patterndocs/generate_pattern_docs.py --pattern ` See [patterndocs/README.md](patterndocs/README.md#adding-a-new-pattern)