← All posts

How I Automated My LeetCode Grind (Without Cheating Myself)

2026-08-14 · 2 min read

automationleetcodenodejsdsa

Consistency is the whole game in DSA prep. Miss three days and the momentum is gone. So I built a safety net: a bot that keeps my practice pipeline moving every single day — while I still do the actual learning.

The pipeline

Every morning a cron job on my VPS:

  1. Fetches the Problem of the Day plus one more problem, alternating Easy/Medium
  2. Generates a Java solution with an LLM
  3. Compiles it with javac — this is the hard gate. If it doesn't compile, it doesn't ship
  4. Pushes to my DSA repo in LeetSync format
  5. Pings me on WhatsApp with the day's summary

The compile gate

The interesting engineering bit. LLM code looks right more often than it is right. The fix is boring and effective:

import { execFileSync } from "node:child_process";

function compiles(file) {
  try {
    execFileSync("javac", [file], { stdio: "pipe", timeout: 30_000 });
    return true;
  } catch {
    return false; // regenerate with the compiler error fed back
  }
}

On failure, the compiler output goes back into the prompt and the bot retries. Two or three rounds almost always converge — and nothing broken ever reaches the repo.

Lessons from running it in production

  • APIs lie about auth. LeetCode's GraphQL endpoint serves most public profile data without a session — but submission code needs a real cookie, and that cookie has no expiry claim, so treat it as "valid until proven dead".
  • Idempotency beats scheduling. The bot checks what already exists before writing. Crashes, re-runs, double-crons — nothing duplicates.
  • A streak you didn't earn is worthless — a pipeline you built isn't. I still solve problems by hand. The bot covers travel days and keeps the repo alive; building it taught me more about APIs, process control and failure handling than a week of grinding would have.

What's next

The same pipeline now feeds this site: the coding dashboard pulls live stats from every platform, and solved problems land in the solutions archive with complexity notes and runtime stats — automatically.