Complexity Analyzer for LeetCode
Manifest V3 Chrome extension analyzing Time & Space Complexity on LeetCode and NeetCode using static AST parsing and hybrid AI providers.
Problem Statement
When practicing data structures and algorithms on platforms like LeetCode and NeetCode, developers often lack immediate, granular feedback on the asymptotic Time and Space Complexity (O(n), O(log n), O(n^2)) of their custom solutions. Existing tools either require manual copy-pasting, demand expensive paid API keys, or rely solely on LLMs that hallucinate complexity for subtle nested recursion or amortized operations.
Architectural Overview & Data Flow
The extension is engineered under Chrome's strict Manifest V3 standard, cleanly decoupling DOM extraction, asynchronous background event routing, local AST parsing, and optional remote AI inference.
LeetCode / NeetCode Active Tab
│
▼ (DOM Content Script: content/leetcodeDetector.js)
Extract Code Snippet & Language (Monaco / CodeMirror Editor)
│
▼ (chrome.runtime Message Passing)
Background Service Worker (background/serviceWorker.js)
├── Settings & Cache Lookup (chrome.storage.local)
│
├── Mode A: Static Offline Analysis (chunks/acorn-*.js)
│ ├── JavaScript / TypeScript: AST traversal & loop/recursion depth scoring
│ └── Multi-Language Heuristics (Python, Java, C++, Go, Rust, Kotlin, Swift)
│
└── Mode B: Hybrid AI-Assisted Inference (Optional Provider Dispatch)
├── Google Gemini (gemini-1.5-flash default)
├── Local Ollama (http://localhost:11434 — zero cloud latency & total privacy)
└── OpenAI / Groq / Anthropic (Fast cloud inference)
│
▼ (chrome.runtime Response)
Extension Popup Interface (popup/popup.js & src/popup/index.html)
Render Complexity (O(Time), O(Space)) + Granular Step-by-Step BreakdownCore Features & Capabilities
leetcode.com, leetcode.cn, and neetcode.io, automatically detecting editor language and extracting active code on demand.chrome.storage.local.Technical Challenges & Engineering Solutions
eval() and string-to-code compilation. Solved by pre-bundling Acorn AST parsers into modular chunks and executing deterministic static AST node traversal.chrome.storage.local so active analysis state and provider credentials survive worker restarts.localhost:11434), allowing privacy-conscious engineers to run local open-source LLMs without leaking code to cloud APIs.Impact & Verification Status
dist/.Stack