Agent skill

LC Cheatsheet
problem → pattern

A solved problem is worth more as a line in the sheet you reach for next time than as one more file in the tree. /lc-cheatsheet files it there: the sheet whose Scope line owns the topic, the pattern it actually belongs under, every snippet run before it lands, the heading anchors the edit moved, and the 中文 overlay kept level.

/lc-cheatsheet 1650 into binary_tree as variation
1  sheet      binary_tree.md, as asked — plus tree_lca_distance.md, whose
              Scope line owns LCA, so the depth goes there and binary_tree
              gets the entry point. Found a bug on the way: the LC 236
              template claimed it solved 1650

2  mode       variation — 1650 breaks one precondition: no root, parent pointers

3  neighbour  matched #### LCA Variant — Smallest Subtree with All Deepest Nodes

4  write      family picker table (236/235/1644/1650/1676), two templates,
              the step trace, the pitfalls · binary_tree.md: Template 6's
              variations table, the 1650 code, the link onward

5  anchors    slugify → #lca-variant--parent-pointers-no-root-lc-1650-
              trailing dash: the star run leaves the space before it

6  test       5 snippets vs the LC examples + a cross-tree pair → None

7  中文        8 sections parked by the edit, all 8 re-keyed → 0 todo

8  verify     build · e2e-check 76/76 · 418 unit tests green

A real run — the LCA variation now in tree_lca_distance, in the order it always happens.

Why a skill and not a habit

Three ways a cheatsheet edit rots

None of these are hypothetical — each one has landed in this repo, and none of them looks wrong in a diff. A sheet is read as authoritative, which is exactly what makes a quiet error in one expensive.

It lands in the wrong sheet

Two sheets can plausibly own “LCA”. Filed into the wrong one it becomes a second copy that drifts, and the Scope lines that exist to prevent that go unread.

Rule: the Scope line decides, not the topic name.

It is appended, not filed

An LC Examples block at the end of the file, re-solving what a template above already solved. That is the Aug 2026 cleanup this repo already paid for once.

Fix: file it under the pattern it belongs to.

The edit breaks what it touched

A changed heading moves its anchor and every link to it dangles. An edited section parks its 中文 translation, and the Chinese page quietly falls back to English.

Both are followed in the same commit.

One argument decides the shape

Four modes

as <mode> is the whole interface. It is inferred from what the sheet already contains, so it is worth passing only to overrule that — and the mode, not the problem, is what determines where the section goes and which tables have to move with it.


      

The sheet itself is inferred too — from the technique the solution uses and from README.md's topic heading for that LC number. into <slug> names one explicitly, and a sheet you name is never left untouched: it gets the entry point — its own table row, the code a reader of that sheet needs, the link onward. If its Scope line does not claim the topic the full section goes to the sheet whose line does, and the report names both — one edit in the common case, two when the topic lives next door.

The half that gets forgotten

What every edit drags behind it

Writing the section is the visible part. These two are what turn a good section into a broken page, and both are mechanical enough to be written down once.

1. The anchors the heading moved

Heading ids come from slugify in the build, which strips a run but not the space before it — so a star run leaves a trailing - on the id. Anchors are computed, never hand-written:

node -e "console.log(require('./site/build-lib.js').slugify('$HEADING'))"
grep -rn "#the-old-anchor" doc/ site/pages/     <- every link that moves with it

e2e-check.js's dangling-#fragment rule is what catches a missed one, so the gate runs rather than the grep being trusted.

2. The 中文 sections the edit parked

There is one markdown tree, the English one; the Chinese pages are a sparse overlay keyed per section. Edit a section and its translation goes missing, so the page falls back to English exactly there:

node script/zh.js sync <slug>      <- park what the edit invalidated
node script/zh.js todo <slug>      <- the sections needing one, keys included
node script/zh.js sync <slug>      <- tidy, after writing them back
node script/zh.js status --write

The check is arithmetic: the sheet must not end up with more untranslated sections than it started with. One LCA edit parked eight of them in a sheet that had been fully translated.

Non-negotiable

The house rules it applies

Straight out of the cheatsheet style guide in CLAUDE.md, which is where they stay — the skill applies them, it does not restate them as a second copy that can drift.

RuleWhy it is a rule
Tag every fencepython, java, or text for traces, diagrams and program output. A bare fence loses highlighting and reads as prose.
IDEA, then complexity# IDEA: <one line> opens a snippet; # time = O(...), space = O(...) is the first comment, stated once per section.
Stars on the headingThe run is rendered as a badge and surfaces 4⭐/5⭐ sections in the page's table of contents. In the prose underneath it is invisible.
Levels never skiph3h4, never h3h5. The table of contents is built from the tree, not from the text.
Each LC number oncePer heading — not … (LC 1650) — LC 1650.
One canonical solutionA second variant needs a stated reason: different complexity, a distinct trick, a different language idiom. Not a different spelling of the same loop.
Match the neighbourThe sibling section is the template — heading depth, fence labels, where complexity sits. 00_template.md wins only where the sheet has drifted.

Bounded on purpose

What it will not do

  • Append an LC Examples section.Re-solving what a template above already solves is how the sheets grew to need a cleanup. It goes under the pattern instead.
  • Open a catch-all.A Missing Google Patterns bucket is a decision deferred, not a section. New material is filed under the pattern it belongs to.
  • Copy a section into a second sheet.A cross-reference is one table row and a link. Two copies of a section are two sections that disagree in six months.
  • Hand back an untested snippet.Every snippet runs against the problem's own examples first. Variants in one section must agree with each other.
  • Touch data/progress.txt.The practice log is your own record and the single source for the review plan — nothing else writes to it.
  • Commit or push unless asked.It writes files, runs the gates, and stops. The commit is yours to shape.

One markdown file, no dependencies

Install

SKILL.md is the whole recipe — nothing to build and no network calls, so the same source runs on any agent that takes a system prompt. Pick yours.

Drop the skill directory into your user-level skills folder and it loads in every repo:

git clone --depth 1 https://github.com/yennanliu/CS_basics.git /tmp/cs_basics
mkdir -p ~/.claude/skills
cp -r /tmp/cs_basics/.claude/skills/lc-cheatsheet ~/.claude/skills/

Already installed inside this repo at .claude/skills/lc-cheatsheet/, so a clone of CS_basics needs no setup at all. Claude Code matches it on the description, or you can call /lc-cheatsheet by name — the directory name is the command.

Under the hood

What is inside

One file. The steps live there and nowhere else — this page describes them, but SKILL.md is what actually runs, so the two cannot drift into two recipes.

  • SKILL.md The whole recipe — the five prime directives, the four modes, the nine steps with their commands, the house rules, what each mode has to make reachable, the do-not list, and the LC 1650 worked example.

Gated in CI by check_skills.py — frontmatter every host can parse, the directory name pinned to the command name, and whether the links on this page still resolve.

The rest of the loop

Where it fits

/lc-add files the solution; /lc-cheatsheet files what you learned from it, which is the part that transfers to the next problem. From there the cheatsheet index lists it, the roadmap points at it from the topic it teaches, search indexes its headings, and LC Coach is the one to ask whether you can now solve the sibling problems the new section names.