|
| 1 | +# Bulk Solution Generation for Missing LeetCode Problems |
| 2 | + |
| 3 | +This document describes the tools and processes for systematically adding AI-generated solutions to all LeetCode problems in the repository. |
| 4 | + |
| 5 | +## Problem Statement |
| 6 | + |
| 7 | +The repository tracks 548 LeetCode problems (as listed in README.md), but many lack AI-generated solutions: |
| 8 | +- **76 problems** have `gpt5-mini.md` files (AI-generated solutions) |
| 9 | +- **472 problems** are missing AI-generated solutions |
| 10 | + |
| 11 | +Some problems have only human-generated solutions (e.g., `jeremymanning.md`), and we want to add AI solutions for all of them. |
| 12 | + |
| 13 | +## Tools Provided |
| 14 | + |
| 15 | +### 1. `identify_missing.py` |
| 16 | + |
| 17 | +Analyzes the repository to identify which problems are missing AI-generated solutions. |
| 18 | + |
| 19 | +**Usage:** |
| 20 | +```bash |
| 21 | +python3 identify_missing.py |
| 22 | +``` |
| 23 | + |
| 24 | +**What it does:** |
| 25 | +- Scans README.md to find all problem numbers |
| 26 | +- Checks for existence of `problems/*/gpt5-mini.md` files |
| 27 | +- Reports which problems are missing AI solutions |
| 28 | +- Creates batch files for processing (50 problems per batch) |
| 29 | +- Saves results to temp directory and batch files |
| 30 | + |
| 31 | +### 2. `auto_solver.py` (Enhanced) |
| 32 | + |
| 33 | +The existing auto_solver script now supports three modes: |
| 34 | + |
| 35 | +**Mode 1: Daily problem (default)** |
| 36 | +```bash |
| 37 | +python3 auto_solver.py |
| 38 | +``` |
| 39 | + |
| 40 | +**Mode 2: Specific problem by ID** |
| 41 | +```bash |
| 42 | +python3 auto_solver.py 123 |
| 43 | +``` |
| 44 | + |
| 45 | +**Mode 3: Bulk solve from file** |
| 46 | +```bash |
| 47 | +# Set your OpenAI API key |
| 48 | +export OPENAI_API_KEY="your-api-key-here" |
| 49 | + |
| 50 | +# Process a batch of problems |
| 51 | +python3 auto_solver.py --bulk /tmp/batch_001.txt |
| 52 | +``` |
| 53 | + |
| 54 | +**What it does:** |
| 55 | +- Fetches problem details from LeetCode API |
| 56 | +- Generates solutions using GPT-5-mini |
| 57 | +- Saves solutions as `problems/{id}/gpt5-mini.md` |
| 58 | +- Handles rate limiting (2 seconds between requests in bulk mode) |
| 59 | +- Reports success/failure for each problem |
| 60 | + |
| 61 | +### 3. GitHub Actions Workflow: `bulk_solver.yml` |
| 62 | + |
| 63 | +Automated workflow for bulk solving problems via GitHub Actions. |
| 64 | + |
| 65 | +**Location:** `.github/workflows/bulk_solver.yml` |
| 66 | + |
| 67 | +**How to use:** |
| 68 | +1. Go to the repository's Actions tab |
| 69 | +2. Select "Bulk Solve Missing LeetCode Problems" |
| 70 | +3. Click "Run workflow" |
| 71 | +4. Configure: |
| 72 | + - **batch_size**: Number of problems to solve (default: 50) |
| 73 | + - **start_index**: Which problem to start from (default: 0) |
| 74 | +5. Click "Run workflow" to start |
| 75 | + |
| 76 | +**What it does:** |
| 77 | +- Automatically identifies missing AI solutions |
| 78 | +- Processes a batch of problems using auto_solver.py |
| 79 | +- Commits and pushes generated solutions |
| 80 | +- Can be run multiple times with different start_index values |
| 81 | + |
| 82 | +**Example workflow runs:** |
| 83 | +- Run 1: start_index=0, batch_size=50 → solves problems 1-50 |
| 84 | +- Run 2: start_index=50, batch_size=50 → solves problems 51-100 |
| 85 | +- Run 3: start_index=100, batch_size=50 → solves problems 101-150 |
| 86 | +- etc. |
| 87 | + |
| 88 | +## Workflow for Adding All Missing Solutions |
| 89 | + |
| 90 | +### Option A: Using GitHub Actions (Recommended) |
| 91 | + |
| 92 | +1. **Initial Analysis** |
| 93 | + ```bash |
| 94 | + python3 identify_missing.py |
| 95 | + ``` |
| 96 | + This shows you how many problems need solutions (currently 472). |
| 97 | + |
| 98 | +2. **Trigger Workflow Runs** |
| 99 | + - Go to Actions → "Bulk Solve Missing LeetCode Problems" |
| 100 | + - Run workflow with: start_index=0, batch_size=50 |
| 101 | + - Wait for completion, then run again with: start_index=50, batch_size=50 |
| 102 | + - Repeat until all problems are processed (10 runs total for 472 problems) |
| 103 | + |
| 104 | +3. **Monitor Progress** |
| 105 | + - Check the Actions tab for workflow status |
| 106 | + - Solutions will be automatically committed to main branch |
| 107 | + |
| 108 | +### Option B: Using Local Script (If you have OpenAI API key) |
| 109 | + |
| 110 | +1. **Setup** |
| 111 | + ```bash |
| 112 | + # Install dependencies |
| 113 | + pip install requests openai httpx |
| 114 | + |
| 115 | + # Set API key |
| 116 | + export OPENAI_API_KEY="your-key-here" |
| 117 | + ``` |
| 118 | + |
| 119 | +2. **Generate batch files** |
| 120 | + ```bash |
| 121 | + python3 identify_missing.py |
| 122 | + ``` |
| 123 | + |
| 124 | +3. **Process batches** |
| 125 | + ```bash |
| 126 | + # Process first batch |
| 127 | + python3 auto_solver.py --bulk /tmp/batch_001.txt |
| 128 | + |
| 129 | + # Commit changes |
| 130 | + git add problems/*/gpt5-mini.md |
| 131 | + git commit -m "Add AI solutions for batch 1" |
| 132 | + git push |
| 133 | + |
| 134 | + # Continue with remaining batches... |
| 135 | + python3 auto_solver.py --bulk /tmp/batch_002.txt |
| 136 | + # ... and so on |
| 137 | + ``` |
| 138 | + |
| 139 | +## Solution Format |
| 140 | + |
| 141 | +All AI-generated solutions follow this format: |
| 142 | + |
| 143 | +```markdown |
| 144 | +# [Problem {ID}: {Title}]({URL}) |
| 145 | + |
| 146 | +## Initial thoughts (stream-of-consciousness) |
| 147 | +[Initial analysis and approach] |
| 148 | + |
| 149 | +## Refining the problem, round 2 thoughts |
| 150 | +[Refined approach, edge cases, complexity analysis] |
| 151 | + |
| 152 | +## Attempted solution(s) |
| 153 | +\`\`\`python |
| 154 | +[Complete Python solution] |
| 155 | +\`\`\` |
| 156 | +- [Notes about approach and complexity] |
| 157 | +``` |
| 158 | + |
| 159 | +## Security Notes |
| 160 | + |
| 161 | +- SSL certificate verification is disabled by default to match the existing `auto_solver.py` pattern (required for environments behind proxies with self-signed certificates) |
| 162 | +- To enable SSL verification in production, set the environment variable: `HTTPX_VERIFY=true` |
| 163 | +- All scripts have been scanned with CodeQL and found no security vulnerabilities |
| 164 | +- API keys are passed via environment variables and never hard-coded |
| 165 | + |
| 166 | +## Technical Details |
| 167 | + |
| 168 | +### API Rate Limiting |
| 169 | +- The script includes 2-second delays between requests |
| 170 | +- This prevents overwhelming the LeetCode or OpenAI APIs |
| 171 | +- For 472 problems, expect ~15-20 minutes per batch of 50 |
| 172 | + |
| 173 | +### Error Handling |
| 174 | +- Problems that fail to fetch are skipped and logged |
| 175 | +- Failed problems are reported at the end |
| 176 | +- You can re-run with just the failed problems |
| 177 | + |
| 178 | +### Network Requirements |
| 179 | +- Requires access to `leetcode.com` (for problem details) |
| 180 | +- Requires access to OpenAI API (for solution generation) |
| 181 | +- GitHub Actions environment has these by default |
| 182 | + |
| 183 | +## Monitoring Progress |
| 184 | + |
| 185 | +After running batches, you can check progress: |
| 186 | + |
| 187 | +```bash |
| 188 | +# Count AI solutions |
| 189 | +find problems -name "gpt5-mini.md" | wc -l |
| 190 | + |
| 191 | +# Re-run analysis |
| 192 | +python3 identify_missing.py |
| 193 | +``` |
| 194 | + |
| 195 | +## Notes |
| 196 | + |
| 197 | +- The `auto_solver.py` script now supports three modes: |
| 198 | + 1. **Daily mode** (default): `python3 auto_solver.py` |
| 199 | + 2. **Single problem**: `python3 auto_solver.py 123` |
| 200 | + 3. **Bulk mode**: `python3 auto_solver.py --bulk file.txt` |
| 201 | +- This bulk solver reuses the existing auto_solver logic, avoiding code duplication |
| 202 | +- Both daily and bulk modes use the same GPT-5-mini model and format |
| 203 | +- Solutions are idempotent - safe to re-run if a problem already has gpt5-mini.md |
0 commit comments