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.
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.
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.
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.
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.
| Rule | Why it is a rule |
|---|---|
| Tag every fence | python, 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 heading | The ⭐ 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 skip | h3 → h4, never h3 → h5. The table of contents is built from the tree, not from the text. |
| Each LC number once | Per heading — not … (LC 1650) — LC 1650. |
| One canonical solution | A 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 neighbour | The 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 Examplessection.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 Patternsbucket 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.
Zip the directory, then Customize → Skills → + → + Create skill → Upload a skill:
cd .claude/skills && zip -r lc-cheatsheet.zip lc-cheatsheet
Leave the YAML frontmatter in SKILL.md intact. description is
what Claude matches your request against when deciding to load the skill on its own;
name is the display label, and the directory name is what supplies the
slash command.
Codex reads AGENTS.md at the repo root automatically. Point it at the skill:
## Updating a cheatsheet
When asked to add an LC problem to a cheatsheet, to document a pattern,
or to update a section under doc/cheatsheet/, follow
`.claude/skills/lc-cheatsheet/SKILL.md`.
A pointer, not a copy — one source of truth means a fix reaches every agent at once.
Same shape in GEMINI.md, or point at it for a single session:
gemini -p "Follow the recipe in .claude/skills/lc-cheatsheet/SKILL.md. \
Add LC 1650 to doc/cheatsheet/binary_tree.md as a variation \
of the LCA template — solution in @lca_iii.py"
Paste SKILL.md in as the system prompt. It is self-contained and has no
references/ to carry. For Cursor or Windsurf, put the Codex pointer above
into a rule file (.cursor/rules/lc-cheatsheet.mdc or the editor's
equivalent).
curl -sL https://raw.githubusercontent.com/yennanliu/CS_basics/master/.claude/skills/lc-cheatsheet/SKILL.md
Three steps are this repo's: the zh.js overlay, the
cheatsheet_meta.json registration and the slugify anchor
calculation. Away from CS_basics they are no-ops — the sheet-choosing, the four
modes and the house rules carry over to any markdown notes tree.
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.