An AI-powered LeetCode problem solver using LangGraph that breaks down problem-solving into specialized agents for comprehensive analysis, strategy development, code generation, testing, and explanation.
The LeetCode Assistant employs a multi-agent architecture where different AI agents collaborate to solve coding problems systematically. Each agent specializes in a specific aspect of the problem-solving process, creating a comprehensive workflow from problem analysis to solution explanation.
- Problem Analysis: Automatically parse and understand LeetCode problem statements
- Strategic Planning: Develop multiple solution approaches and select optimal strategies
- Code Generation: Generate clean, efficient code implementations
- Automated Testing: Execute and validate solutions against test cases
- Solution Explanation: Provide detailed explanations of algorithms and complexity analysis
- CLI Interface: Easy-to-use command-line interface with rich formatting
- Jupyter Integration: Interactive notebooks for experimentation and development
leetcode-assistant/
├── src/
│ ├── agents/ # Specialized AI agents
│ │ ├── problem_analyzer.py # Analyzes problem statements
│ │ ├── solution_strategist.py # Develops solution strategies
│ │ ├── code_generator.py # Generates code implementations
│ │ ├── test_runner.py # Executes and validates solutions
│ │ └── explainer.py # Provides detailed explanations
│ ├── graph/ # LangGraph workflow orchestration
│ │ ├── state.py # State management between agents
│ │ └── workflow.py # Multi-agent workflow definition
│ ├── utils/ # Helper utilities
│ │ ├── leetcode_parser.py # LeetCode problem format parsing
│ │ └── code_executor.py # Safe code execution environment
│ └── cli.py # Command-line interface
├── tests/ # Test suite
├── notebooks/ # Jupyter notebooks for development
│ └── demo.ipynb # Demo and experimentation notebook
├── requirements.txt # Project dependencies
├── pyproject.toml # Project configuration
└── README.md # This file
The system follows a sequential multi-agent approach:
- Problem Analyzer - Parses problem statement, extracts constraints, identifies problem type
- Solution Strategist - Analyzes multiple approaches, considers trade-offs, selects optimal strategy
- Code Generator - Implements the solution with clean, efficient code
- Test Runner - Executes solution against provided and edge case tests
- Explainer - Provides comprehensive explanation of approach, complexity, and key insights
The workflow uses a shared state object that gets passed between agents, accumulating:
- Problem details and constraints
- Generated strategies and selected approach
- Code implementation and test results
- Explanations and analysis
-
Clone the repository:
git clone <repository-url> cd leetcode-assistant
-
Create and activate virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Install in development mode:
pip install -e .
# Basic usage
leetcode-assistant
# Or run directly
python -m src.cli
Start Jupyter Lab for interactive development:
jupyter lab
Open notebooks/demo.ipynb
to see examples and experiment with the system.
pytest
black src/ tests/
isort src/ tests/
mypy src/
- LangGraph: Multi-agent workflow orchestration
- LangChain: LLM integration and agent framework
- OpenAI/Anthropic: Language model providers
- Click: Command-line interface framework
- Rich: Enhanced terminal output and formatting
- BeautifulSoup: Web scraping for LeetCode problems
- Pydantic: Data validation and serialization
- Jupyter: Interactive development environment
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass and code is formatted
- Submit a pull request
[License information to be added]
- Support for multiple programming languages
- Integration with LeetCode API
- Performance benchmarking and optimization
- Visual solution explanations
- Contest mode with time constraints
- Solution comparison and ranking