Skip to content

prakhxr0/Leetcode-Solver-Bot

Repository files navigation

Leetcode Solver Bot

Leetcode Solver Bot

Node.js TypeScript Puppeteer C++ License Docker

Leetcode Solver Bot is a fully local automated LeetCode solver that solves and submits 1,465+ LeetCode problems automatically — no API key needed. It reads solutions from a local archive, injects them into LeetCode's Monaco editor via Puppeteer browser automation, and submits — all from a tui. Useful for boosting your LeetCode profile stats and problem-solved count.

"I came, I saw, I copied the optimal solution." ~ Julius Caesar, probably



Demo GIF


✦ Features

Feature Detail
1,465+ C++ solutions Local JSON archive — no network call for the solution itself
Cloudflare bypass Headed Chrome with persistent session; manual login once, then it's remembered
Monaco API injection Writes directly into LeetCode's editor API with retry + post-injection verification
Ink TUI React-based terminal UI with live progress, verdicts, and a summary screen
Smart rate limiting 8s between submissions, 15s cooldown every 5 problems — time estimate shown upfront
Verdict detection Polls "Judging…" state transitions to capture the actual result reliably
Skip logic Auto-skips already-solved and premium problems via GraphQL status check
Docker support Self-contained container with Chromium

⚡ How It Works

Workflow Diagram Phase breakdown:

  1. Email setup — TUI asks for your LeetCode email (saved for future runs)
  2. Cloudflare login — First run opens headed Chrome; complete challenge manually
  3. Problem selection — GraphQL checks solved/premium status. Reads solution from data/problems/ locally.
  4. Browser setup — Puppeteer with a persistent Chrome profile. Sessions survive restarts.
  5. Navigation — Loads the problem URL, waits on domcontentloaded (not networkidle2 — avoids Cloudflare hangs).
  6. Injection — Switches editor language to C++ if needed. Injects via Monaco API and verifies with value.includes('class Solution') && value.length > 50.
  7. Submission — Clicks submit, waits for Judging… to appear then disappear, reads result.
  8. Rate limiting — 8s delay between each problem. 15s cooldown every 5th. Time estimate printed before the run starts.

🚀 Setup

Docker (Recommended)

No Node.js or Chrome needed on your host. The image ships with Chrome for Testing, all dependencies, and the problem archive — everything works out of the box.

1. Pull the image

docker pull prakhxr/leetcode-solver-bot

Docker Hub

2. Run

docker run -it \
  -v $(pwd)/UserData:/app/UserData \
  --network host \
  prakhxr/leetcode-solver-bot

A Chrome window opens. Enter your LeetCode credentials and complete any Cloudflare challenge. After login, close the bot — your session is saved to ./UserData/ and reused from here on.

Or use docker compose (from a cloned repo):

docker compose run leetcode

npm (Local Development)

Requires Node.js 18+ and a local Chrome for Testing download.

1. Clone & install

git clone https://github.com/prakhxr0/Leetcoder.git
cd Leetcoder
npm install

2. Download Chrome for Testing

The bot uses a project-local Chrome binary so it doesn't interfere with your system browser.

Linux (x64):

mkdir -p .chromium && cd .chromium
curl -sL "https://storage.googleapis.com/chrome-for-testing-public/121.0.6167.85/linux64/chrome-linux64.zip" -o chrome.zip
unzip -q chrome.zip && rm chrome.zip
chmod +x chrome-linux64/chrome
cd ..

macOS (Apple Silicon):

mkdir -p .chromium && cd .chromium
curl -sL "https://storage.googleapis.com/chrome-for-testing-public/121.0.6167.85/mac-arm64/chrome-mac-arm64.zip" -o chrome.zip
unzip -q chrome.zip && rm chrome.zip
cd ..

macOS (Intel):

mkdir -p .chromium && cd .chromium
curl -sL "https://storage.googleapis.com/chrome-for-testing-public/121.0.6167.85/mac-x64/chrome-mac-x64.zip" -o chrome.zip
unzip -q chrome.zip && rm chrome.zip
cd ..

Windows (PowerShell):

New-Item -ItemType Directory -Force -Path .chromium
cd .chromium
Invoke-WebRequest -Uri "https://storage.googleapis.com/chrome-for-testing-public/121.0.6167.85/win64/chrome-win64.zip" -OutFile chrome.zip
Expand-Archive chrome.zip -DestinationPath .
Remove-Item chrome.zip
cd ..

3. Configure .env

Create a .env file in the project root:

USER_EMAIL=your-email@example.com
GOOGLE_CHROME_EXECUTABLE_PATH=/full/path/to/Leetcoder/.chromium/chrome-linux64/chrome

Linux: /home/you/projects/Leetcoder/.chromium/chrome-linux64/chrome

macOS: .chromium/chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing

Windows: .chromium\chrome-win64\chrome.exe

4. First run (login)

npm start

A Chrome window opens. Enter your LeetCode credentials and complete any Cloudflare challenge. After login, close the bot — your session is saved in ./UserData/ and reused from here on.

Platform notes

Platform Notes
Linux Works out of the box with X11
macOS Install XQuartz: brew install --cask xquartz, then logout/login
WSL2 WSLg is built-in on Windows 11, works automatically
Windows Use PowerShell or Git Bash

⚙️ Configuration

Rate limiting

Parameter Value Notes
Submission delay 8s Between every problem
Cooldown period 15s Triggered every 5 problems
Time estimate count × 10s + ⌊count/5⌋ × 15s Shown before the run starts

Adding solutions

Drop new solutions into data/problems/ as JSON files following the existing format. The SolvedProblems.json tracker is updated automatically after each successful submission.


🛠️ Tech Stack

Frontend (TUI)
  • React — Component model for terminal UI
  • Ink — Renders React components into the terminal
  • TypeScript — Type safety across TUI components
  • tsx — JSX transpilation without a build step
Backend (Solver)
  • Puppeteer — Browser automation + Monaco API access
  • Node.js — Runtime for the entire bot
  • GraphQL — LeetCode's own API for problem status checks
Data
  • JSON files — 1,465 C++ solution files in data/problems/
  • SolvedProblems.json — Local tracker to avoid re-submission
Deployment
  • Docker — Self-contained container with Chromium
  • Docker Compose — Easy setup and configuration
  • Volumes — Persistent Chrome profile and solved problems

⚠️ Known Limitations

  • Cloudflare — Requires a one-time manual login. After that, the session is remembered.
  • Rate delays — Fixed cooldowns; may need tuning for different network conditions.
  • Premium problems — Detected via GraphQL and skipped automatically. Can't solve what you can't see.
  • Session expiry — Long breaks may require re-authentication.
  • Docker image size — ~500MB-1GB due to bundled Chromium and problem archive.

🤝 Contributing

  1. Add new C++ solutions to data/problems/
  2. Follow the existing JSON format
  3. Open a PR with what you added

MIT License · built with Puppeteer, Ink, and zero remorse

If this saved your grind, leave a ⭐

About

Automated LeetCode solver bot - Fully local, no API key required - solves and submits 1,400+ LeetCode problems in C++ automatically using Puppeteer and Monaco editor injection. Boost your LeetCode profile stats for free.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors