~/vimal-jain
Chrome Extension • MV3Nov 2026

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 Breakdown

Core Features & Capabilities

•Automatic Editor Detection: Content scripts listen on leetcode.com, leetcode.cn, and neetcode.io, automatically detecting editor language and extracting active code on demand.
•Zero-Config Offline AST Analysis: Ships with an offline Acorn AST parser for JavaScript/TypeScript, enabling instantaneous complexity analysis without requiring external API keys.
•Hybrid AI Provider Architecture: Pluggable AI engine supporting Google Gemini, OpenAI, Groq, Anthropic, and local Ollama instances for private offline inference.
•Multi-Language Coverage: Broad heuristic and AST parsing across 10 major programming languages (Python 3, JS, TS, Java, C++, C#, Go, Rust, Kotlin, Swift).
•Standalone Custom Code Tester: Built-in editor inside the popup allows analyzing arbitrary code snippets outside LeetCode.
•Persistent Preference Management: Seamless theme switching (auto/light/dark) and API configuration persisted via chrome.storage.local.

Technical Challenges & Engineering Solutions

•Manifest V3 CSP & Dynamic Evaluation: Chrome Manifest V3 strictly prohibits eval() and string-to-code compilation. Solved by pre-bundling Acorn AST parsers into modular chunks and executing deterministic static AST node traversal.
•Non-Persistent Background Service Worker: Background workers in MV3 terminate when idle. Architected stateless message handlers paired with chrome.storage.local so active analysis state and provider credentials survive worker restarts.
•Multi-Platform DOM Extraction: LeetCode and NeetCode use dynamic SPA architectures and virtualized code editors (Monaco/CodeMirror). Built robust fallback selectors to reliably extract buffer text without breaking on DOM mutations.
•Privacy-First Local Inference: Integrated support for local Ollama endpoints (localhost:11434), allowing privacy-conscious engineers to run local open-source LLMs without leaking code to cloud APIs.

Impact & Verification Status

•Production-ready Manifest V3 unpacked build in dist/.
•Verified functional across LeetCode, LeetCode CN, and NeetCode.
•Zero external dependencies required for base static analysis mode.

Stack

TypeScriptJavaScriptChrome Extension MV3AST AnalysisAcorn ParserGoogle Gemini APIOllamaGroqOpenAI APIService WorkersTailwind CSS