Skip to content

yong-huang/LeetCodeVisual

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LeetCode Visualizer

A CLI-based algorithm visualization tool for 100 LeetCode problems (1-100) with step-by-step execution tracking and rich terminal displays.

Features

  • 100 Problems: Complete implementations of LeetCode problems 1-100
  • Step-by-Step Visualization: Watch algorithms execute with detailed explanations
  • Rich Terminal UI: Beautiful interface using the rich library
  • Customizable Speed: Control visualization speed with --interval
  • Comprehensive Tests: 1288 test cases with 100% pass rate
  • Educational Focus: Detailed step tracking makes algorithm learning easier

Quick Start

Installation

git clone https://github.com/<your-username>/LeetCodeVisual.git
cd LeetCodeVisual
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt

Basic Usage

# Run with default example values
python main.py 1

# Run with custom arguments
python main.py 1 2 7 11 15 9

# Control visualization speed
python main.py 1 --interval 0        # No delay
python main.py 1 --interval 1.0      # Fast (1s)
python main.py 1 --interval 3.0      # Slow (3s)

# Show help
python main.py --help
python main.py --help 1              # Help for specific problem

Examples

python main.py 1 2 7 11 15 9        # Two Sum
python main.py 20 "()[]{}"           # Valid Parentheses
python main.py 92 1 2 3 4 5         # Reverse Linked List II
python main.py 98 2 1 3             # Validate Binary Search Tree
python main.py 100 1 2 3 : 1 2 3   # Same Tree (colon separates two trees)

Demo: Problem 12 - Integer to Roman

python main.py 12 58

Architecture

Three-layer architecture for clean separation of concerns:

┌─────────────────────────────────────────┐
│     Dispatcher Layer (main.py)          │
│  - Argument parsing & problem routing   │
└──────────────┬──────────────────────────┘
               │
┌──────────────▼──────────────────────────┐
│   Visualizer Layer (visualizer.py)      │
│  - Rich UI presentation                 │
│  - Step-by-step display                 │
└──────────────┬──────────────────────────┘
               │
┌──────────────▼──────────────────────────┐
│     Solver Layer (solver.py)            │
│  - Pure algorithm logic (no UI deps)    │
│  - Step data generation                 │
└─────────────────────────────────────────┘

Each problem lives in its own directory:

problems/
├── problem_1/
│   ├── __init__.py          # Exports solver and visualizer
│   ├── solver.py            # Algorithm implementation
│   └── visualizer.py        # UI presentation
├── problem_2/
│   └── ...
└── problem_100/
    └── ...

Input Formats

Input Type Example Format
Single integer python main.py 7 3 Direct value
Array python main.py 1 2 7 11 15 9 Space-separated
String python main.py 3 abcabcbb Direct or quoted
Multiple arrays python main.py 2 2 4 3 : 5 6 4 Colon-separated
Linked list python main.py 206 1 2 3 4 5 Space-separated values
Tree python main.py 100 1 2 3 : 1 2 3 Colon-separated per tree

Testing

pytest                                # Run all tests (1288)
pytest tests/test_problem_1.py        # Run specific problem
pytest -v                             # Verbose output
pytest --tb=short -q                   # Quick run

Development

See CLAUDE.md for detailed development guidelines, code style conventions, and architecture patterns.

Adding a New Problem

  1. Create problems/problem_N/ directory
  2. Implement solver.py with algorithm logic and step tracking
  3. Implement visualizer.py with rich UI presentation
  4. Create __init__.py to export both classes
  5. Add routing in main.py
  6. Create tests in tests/test_problem_N.py

Requirements

  • Python 3.9+
  • rich (CLI visualization)
  • pytest (testing)

License

MIT

Contributing

Contributions are welcome! Please ensure:

  • All tests pass (pytest)
  • Code follows established patterns (see CLAUDE.md)
  • Comprehensive test coverage for new features

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages