Skip to content

Thissutek/leetcode-assistant

Repository files navigation

LeetCode Assistant

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.

Project Overview

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.

Features

  • 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

Project Structure

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

Architecture

Multi-Agent Workflow

The system follows a sequential multi-agent approach:

  1. Problem Analyzer - Parses problem statement, extracts constraints, identifies problem type
  2. Solution Strategist - Analyzes multiple approaches, considers trade-offs, selects optimal strategy
  3. Code Generator - Implements the solution with clean, efficient code
  4. Test Runner - Executes solution against provided and edge case tests
  5. Explainer - Provides comprehensive explanation of approach, complexity, and key insights

State Management

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

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd leetcode-assistant
  2. Create and activate virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install dependencies:

    pip install -r requirements.txt
  4. Install in development mode:

    pip install -e .

Usage

Command Line Interface

# Basic usage
leetcode-assistant

# Or run directly
python -m src.cli

Jupyter Notebooks

Start Jupyter Lab for interactive development:

jupyter lab

Open notebooks/demo.ipynb to see examples and experiment with the system.

Development

Running Tests

pytest

Code Formatting

black src/ tests/
isort src/ tests/

Type Checking

mypy src/

Technology Stack

  • 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

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass and code is formatted
  6. Submit a pull request

License

[License information to be added]

Future Enhancements

  • 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages