A powerful Chrome/Brave extension that provides AI-powered code review and complexity analysis for LeetCode in the browserβguided hints that build reasoning without revealing full solutions.Follows the authorβs approach, detects edge cases and performance pitfalls, and renders unlimited, realβtime time/space complexity graphsβpowered by Gemini.
- π€ AI Code Review - Get intelligent feedback and hints on your LeetCode solutions
- π Time & Space Complexity Analysis - Beautiful visual graphs with Big-O notation
- π¨ Dark UI - Seamless integration with LeetCode's interface
- β¨οΈ Keyboard Shortcut - Toggle panel with `Ctrl + ``
- π Powered by Gemini 2.5 Pro - Advanced AI analysis
- π Privacy First - Your code is only sent to Gemini API, nothing stored
The floating assistant panel with Review, Time, and Space buttons
AI-powered code review with hints and suggestions
Interactive time complexity visualization
Interactive space complexity visualization
- Node.js (v16 or higher)
- Chrome or Brave browser
- Google Gemini API key (Get one here)
git clone https://github.com/yourusername/leetcode-ai-assistant.git
cd leetcode-ai-assistant# Install root dependencies
npm install
# Install server dependencies
cd server
npm install
cd ..Create/edit server/.env file:
PORT=5055
GEMINI_API_KEY=your_gemini_api_key_here
GEMINI_MODEL=gemini-2.5-proπ‘ Get your API key: Visit Google AI Studio
npm startThis command will:
- β Build the React visualization component
- β
Copy build files to
server/public - β
Start the Express server on
http://localhost:5055
You should see:
Server listening on http://localhost:5055
[INFO] Using Gemini model: gemini-2.5-pro
-
Open your browser and navigate to:
- Chrome:
chrome://extensions - Brave:
brave://extensions
- Chrome:
-
Enable Developer mode (toggle in top-right corner)
-
Click "Load unpacked"
-
Select the
extensionfolder from this project -
You should see the extension installed! π
- Go to any LeetCode problem
- Write your solution in the code editor
- The assistant panel will appear in the top-right corner
- Click buttons to analyze your code!
The extension adds a floating panel to LeetCode with three main buttons:
| Button | Function | Description |
|---|---|---|
| Review | AI Code Review | Get hints, suggestions, and guidance on your solution |
| Time | Time Complexity | Visualize time complexity with interactive graph |
| Space | Space Complexity | Visualize space complexity with interactive graph |
- `Ctrl + `` - Toggle panel visibility (show/hide)
- Write your solution in LeetCode's editor
- Click "Review" to get AI feedback
- Click "Time" to see time complexity analysis
- Press `Ctrl + `` to hide panel while coding
- Press `Ctrl + `` again to show panel
leetcode-ai-assistant/
βββ extension/ # Chrome Extension
β βββ manifest.json # Extension configuration (Manifest V3)
β βββ content.js # Main content script (injected into LeetCode)
β βββ pageBridge.js # Bridge for code extraction
β βββ icon/ # Extension icons
β
βββ server/ # Express Backend
β βββ src/
β β βββ index.js # API server + static file serving
β βββ .env # Environment variables (API keys)
β βββ package.json # Server dependencies
β βββ public/ # Built React app (auto-generated)
β
βββ src/ # React Visualization App
β βββ Components/
β β βββ ComplexityGraph.jsx # Main graph component
β β βββ Input.jsx # Input component
β β βββ Output.jsx # Output component
β βββ App.jsx # React root
β
βββ package.json # Root dependencies
βββ vite.config.js # Vite build configuration
βββ README.md # This file
βββββββββββββββββββ
β LeetCode β
β Website β
ββββββββββ¬βββββββββ
β
β (Content Script Injection)
β
ββββββββββΌβββββββββ
β Extension β
β content.js βββββ Ctrl+` keyboard listener
ββββββββββ¬βββββββββ
β
β (HTTP Requests)
β
ββββββββββΌβββββββββ
β Express Server β
β localhost:5055 β
ββββββββββ¬βββββββββ
β
β (API Calls)
β
ββββββββββΌβββββββββ
β Gemini API β
β (Google AI) β
βββββββββββββββββββ
- Injects floating panel into LeetCode pages
- Captures code from editor using message passing
- Handles button clicks and keyboard shortcuts
- Manages panel visibility state
- Endpoints:
POST /api/review- AI code reviewPOST /api/complexity- Complexity analysisGET /health- Health check
- Features:
- CORS enabled for cross-origin requests
- Serves React app as static files
- Gemini API integration
- Interactive complexity graphs using Chart.js
- LaTeX rendering for Big-O notation using KaTeX
- Styled with TailwindCSS
- Embedded in iframe within extension panel
Request:
{
"code": "class Solution:\n def twoSum(self, nums, target):\n ...",
"language": "python3"
}Response:
{
"review": "Your approach is correct! Here are some hints:\n- Consider edge cases...\n- Time complexity can be improved..."
}Request:
{
"code": "class Solution:\n def twoSum(self, nums, target):\n ...",
"language": "python3"
}Response:
{
"summary": "Your solution uses a nested loop approach...",
"complexity": {
"time": "O(nΒ²)",
"space": "O(1)",
"explanation": "Two nested loops iterate through the array..."
}
}For faster development with hot module replacement:
Terminal 1 - React Dev Server:
npm run devThis starts Vite dev server on http://localhost:5173
Terminal 2 - Backend Server:
cd server
npm run devThis starts Express with nodemon on http://localhost:5055
Note: Update extension/content.js line 315 to point to dev server:
iframe.src = 'http://localhost:5173'; // Dev modenpm run buildBuilds React app to server/public/ for production deployment.
Extension Console:
- Right-click extension icon β "Inspect popup"
- Check console for logs prefixed with
[LC Assistant]
Content Script Console:
- Open DevTools on LeetCode page
- Check console for extension logs
Server Logs:
- Check terminal where
npm startis running - Look for Gemini API errors or CORS issues
- React 19 - UI framework
- Chart.js - Graph visualization
- KaTeX - LaTeX math rendering
- TailwindCSS - Styling
- Vite - Build tool
- Express.js - Web server
- Node.js - Runtime
- node-fetch - HTTP client
- dotenv - Environment variables
- cors - Cross-origin resource sharing
- Google Gemini 2.5 Pro - AI model
- Generative Language API - Gemini REST API
- Manifest V3 - Chrome Extension format
- Content Scripts - DOM injection
- Shadow DOM - Style isolation
- β No data storage - Code is only sent to Gemini API
- β API key in .env - Never hardcoded or exposed
- β Local server - Runs on your machine
- β HTTPS to Gemini - Encrypted API communication
- β No tracking - No analytics or telemetry
Problem: Extension shows "Review failed. See console."
Solutions:
- Make sure server is running:
npm start - Check server is on port 5055:
http://localhost:5055/health - Verify
.envfile exists inserver/folder - Check browser console for CORS errors
Problem: Panel doesn't show on LeetCode
Solutions:
- Reload extension in
chrome://extensions - Hard refresh LeetCode page (
Ctrl + Shift + R) - Check extension is enabled
- Open console and look for
[LC Assistant]logs
Problem: "Gemini review failed" or HTTP 400/403
Solutions:
- Verify API key is correct in
server/.env - Check API key has Gemini API enabled
- Verify you haven't exceeded quota
- Try different model:
gemini-1.5-flash
Problem: Panel covers code editor
Solution:
- Press `Ctrl + `` to hide/show panel
- Panel is toggleable anytime!
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- LeetCode - For the amazing platform
- Google Gemini - For the powerful AI API
- Chart.js - For beautiful graphs
- KaTeX - For LaTeX rendering
Have questions or suggestions? Feel free to open an issue!
Made with β€οΈ for the LeetCode community
