leetctl 0.4.0

LeetCode command-line interface in Rust, with curated problem sets and filtered random picking.
Documentation
# Problem sets

`leetctl` ships eleven curated problem lists. They are plain TOML under [`data/sets/`](../data/sets),
compiled into the binary, so filtering by one needs no network call and no LeetCode Premium
subscription.

```sh
leetctl sets                                  # what's available
leetctl list --set blind75 --stat             # your progress through a set
leetctl pick --set blind75 --difficulty medium  # random pick from a set
```

## What's in the box

| Slug | Name | Problems | Source | License |
| --- | --- | ---: | --- | --- |
| `blind75` | Blind 75 | 75 | [neetcode-gh/leetcode]https://github.com/neetcode-gh/leetcode | MIT |
| `neetcode150` | NeetCode 150 | 150 | same | MIT |
| `neetcode250` | NeetCode 250 | 250 | [neetcode.io practice page]https://neetcode.io/practice/practice/neetcode250 | NeetCode, identifiers only |
| `neetcode-all` | NeetCode All | 450 | [neetcode-gh/leetcode]https://github.com/neetcode-gh/leetcode | MIT |
| `top-interview-150` | Top Interview 150 | 150 | LeetCode study plan | LeetCode, identifiers only |
| `top-100-liked` | Top 100 Liked | 100 | LeetCode study plan | LeetCode, identifiers only |
| `leetcode-75` | LeetCode 75 | 75 | LeetCode study plan | LeetCode, identifiers only |
| `google` | Google | 488 | [hxu296/leetcode-company-wise-problems-2022]https://github.com/hxu296/leetcode-company-wise-problems-2022 | MIT |
| `facebook` | Meta / Facebook | 371 | same | MIT |
| `amazon` | Amazon | 592 | same | MIT |
| `microsoft` | Microsoft | 363 | same | MIT |

### The company lists are a 2022 snapshot — read this before trusting them

LeetCode's live company tags are a **Premium** feature and are not available to this tool. The four
company sets come instead from a community-collected snapshot of which problems carried each
company's tag in **2022**. Treat them as "problems that were being asked around 2022", not as a
current signal.

They are membership lists, not ranked frequency lists: the upstream data carries an occurrence
count, but this tool samples uniformly and sorts by problem id, so that ranking is not stored. Each
file records `source_as_of = "2022"`, and `leetctl sets --sources` prints it.

### Where the NeetCode lists come from

`blind75`, `neetcode150`, and `neetcode-all` come from NeetCode's MIT-licensed data file,
[`.problemSiteData.json`][ncdata] — 450 entries, flagged for those first two lists only.

**`neetcode250` is not in that file.** It exists only in the neetcode.io site itself, whose problem
table is compiled into an Angular bundle rather than served as JSON (`neetcode.io/api/problems`
returns the site's HTML shell). The generator therefore scrapes the content-hashed bundle name off
the practice page, fetches the bundle, and reads the problem object literals out of it:

```js
{problem:"Two Sum",pattern:"Arrays & Hashing",link:"two-sum/",...,neetcode250:!0,ncLink:"two-integer-sum/"}
```

`link` is the LeetCode slug and is what gets joined on. `ncLink` is NeetCode's own slug for the
same problem, and is deliberately ignored — it is a different naming scheme entirely
(`two-sum` vs `two-integer-sum`, `contains-duplicate` vs `duplicate-integer`).

That bundle also carries 973 problems and its own `blind75` / `neetcode150` flags. The generator
checks those against the MIT data file and **fails if the two sources disagree**, because mixing
sources is only safe while they agree; today they match exactly. It also asserts the lists still
nest (blind75 ⊆ neetcode150 ⊆ neetcode250), which `src/sets/mod.rs` re-checks at test time.

`neetcode-all` stays at the MIT file's 450 — every problem NeetCode publishes a *solution* for. The
site's own catalog is larger (973), so "All" here means "all solved", not "everything on the site".

[ncdata]: https://github.com/neetcode-gh/leetcode/blob/main/.problemSiteData.json

### Premium problems

Some sets contain LeetCode Premium problems (e.g. *Encode and Decode Strings*, *Walls and Gates*).
They stay in the sets — they are genuinely part of those lists — but show as locked and cannot be
fetched without a subscription. Counts, measured against a current problem cache:

| Set | Locked |
| --- | ---: |
| `blind75` | 6 |
| `neetcode150` | 7 |
| `neetcode250` | 7 |
| `neetcode-all` | 9 |
| `google` | 80 |
| `top-interview-150`, `top-100-liked`, `leetcode-75` | 0 |

Filter them out with the `L` query flag:

```sh
leetctl pick --set neetcode150 --query L
```

## File format

One file per set. Every entry carries both the frontend id and the slug; `fid` is what problems are
actually filtered on, and `slug` is there so the files stay readable and diff meaningfully when
regenerated.

```toml
# @generated by scripts/gen_sets.py — do not edit by hand.
slug = "blind75"
name = "Blind 75"
description = "The original Blind 75 list, as tracked by NeetCode."
source_url = "https://github.com/neetcode-gh/leetcode"
source_license = "MIT"
source_as_of = "2026-08-17"   # vintage of the data
generated_at = "2026-08-17"   # when it was last fetched

problems = [
  { fid = 217, slug = "contains-duplicate" },
  { fid = 242, slug = "valid-anagram" },
]
```

Curated lists keep their source's curriculum order. The company lists are sorted by `fid`, because
their upstream order carries a frequency ranking this tool does not use — sorting makes regenerated
diffs reviewable.

`source_as_of` is a plain date rather than a `stale` boolean: nothing has to decide when a set stops
being current, and the field cannot itself go out of date.

## Regenerating

```sh
python3 scripts/gen_sets.py
```

Standard library only, no virtualenv. It fetches every source, resolves each problem, rewrites all
eleven files, and prints a per-set count.

**Generation fails rather than shipping a short set.** If any slug does not resolve, or a set does
not come out at the size recorded in `EXPECTED_COUNTS`, the script exits non-zero and writes
nothing for that set — otherwise a "Blind 75" holding 74 problems could ship unnoticed. A genuine
upstream change means updating `EXPECTED_COUNTS` deliberately, after reviewing the diff. The same
counts are asserted again by the Rust tests in `src/sets/mod.rs`.

**Slugs are the join key, fids come from LeetCode.** Sources disagree about ids — the company CSVs
carry only a URL, and one NeetCode entry has a malformed id field (`135-candy` where every other
entry is zero-padded to four digits). So the generator pulls the authoritative slug → frontend id
index from `https://leetcode.com/api/problems/all/` and joins on that. A slug that does not resolve
fails the run with an explanation, and is never guessed at.

LeetCode has renamed seven problems since the 2022 company data was collected (`implement-strstr` →
`find-the-index-of-the-first-occurrence-in-a-string`, `friend-circles` → `number-of-provinces`, and
five others). `RENAMED_SLUGS` in the generator maps them across; each target was checked against the
live index by frontend id rather than inferred from the old name. Without that map, 13 entries drop
out of the company sets.

## Adding a set

1. Add a source and an entry to the relevant table in `scripts/gen_sets.py`.
2. Run it, and commit both the script change and the generated `data/sets/<slug>.toml`.
3. Add its size to `EXPECTED_COUNTS` in the generator, and to the matching table in
   `src/sets/mod.rs`'s tests.
4. Register the file in `REGISTRY` in `src/sets/mod.rs` — this is what makes the slug valid on the
   command line and in shell completions.
5. Add a row to the table above.

Sets must come from a source that permits redistribution. The four sources shipped today are
MIT-licensed or fetched from LeetCode's own public endpoints, and only problem identifiers are
stored — never problem text. Each set records its source and licence, and `LICENSE` carries the
upstream notices.