Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ worked". A control shows a list back as `1, 2, 3` by itself; give it a
string — `?approach=heap&step=7&lang=python&nums=1,2,3` — so a mode's `id`
and a control's `key` are part of every link a reader shares. Keep them
short and stable once published, and make `parse(format(v))` give back `v`
for every control, so a shared link reopens the same input. The part 1 widget uses `presetChips(sets, active)` for its chips
for every control, so a shared link reopens the same input. A link is input
anyone can write, and narration, notes and widget lines are HTML: a value from
a control that allows `<`, `>` or `&` goes through `esc()` (kit.js) before it is
spliced into one (stage.js shapes and the hover tip escape on their own). A
widget redraws on every pick; the stepper puts focus back on the redrawn chip
or cell with the same `data-*` attributes, so give each clickable one a stable
`data-*` key (`data-set`, `data-i`). The part 1 widget uses `presetChips(sets, active)` for its chips
(the active one is `aria-pressed`, which lesson.css draws as selected; a
widget's own toggle chips should set it too) and `widgetLabel(text)` for the
note beside its heading. Anything a lesson draws uses a class from `lesson.css`, `kit.css`
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Actions tab to verify all of them.
#
# The runner is pinned to ubuntu-24.04 (ubuntu-latest moves to 26.04, which
# may not carry a prebuilt Ruby 3.1), and Node 24, Ruby 3.1 and Python 3.12 are pinned to the versions the badges were
# may not carry a prebuilt Ruby 3.1), and Node 24, Ruby 3.1, Python 3.12 and Rust 1.98 are pinned to the versions the badges were
# measured with: a stack depth a badge quotes ("overflows Ruby 3.1's default
# stack past 7,687 deep") only holds for that runtime. Change them together
# with the badges.
Expand Down Expand Up @@ -154,6 +154,6 @@ jobs:
with:
ruby-version: '3.1'
- name: Pull the Go and Rust images run.py uses
run: docker pull -q golang:1.23-alpine && docker pull -q rust:1-slim
run: docker pull -q golang:1.23-alpine && docker pull -q rust:1.98-slim
- name: Every listing, five languages, then the walkthroughs
run: python3 scripts/verify/run.py "${{ matrix.slug }}" --strict
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ code they can trust. So three rules are firm:

- Node 20+, Python 3.10+, Ruby 3
- Docker, for Go and Rust. The verifier runs them in `golang:1.23-alpine` and
`rust:1-slim`, and reports them as *skipped*, not passed, when Docker isn't
`rust:1.98-slim`, and reports them as *skipped*, not passed, when Docker isn't
running.

## Building a page, step by step
Expand Down
4 changes: 3 additions & 1 deletion scripts/audit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ async function keysAndLink(page, url) {
const found = [];
await page.goto(url);
await page.waitForSelector('#lesson .atab');
await page.waitForTimeout(300); // the address is written after a 150ms debounce
if (new URL(page.url()).search) found.push(`an untouched page has a query: ${new URL(page.url()).search}`);
const count = () => page.$eval('#lesson [data-count]', (e) => e.textContent.trim());
const playLabel = () => page.$eval('#lesson [data-act="play"]', (e) => e.textContent.trim());
Expand All @@ -181,7 +182,8 @@ async function keysAndLink(page, url) {
await page.keyboard.press(' ');
if (!(await count()).startsWith('2 /') || (await playLabel()) !== 'Play') {
found.push(`space on a focused Next: step ${await count()}, play button "${await playLabel()}" (want step 2, not playing)`);
await page.click('#lesson [data-act="play"]').catch(() => {});
// stop playback if space started it; clicking a stopped Play would start it
if ((await playLabel()) !== 'Play') await page.click('#lesson [data-act="play"]').catch(() => {});
}
if ((await page.$$('#lesson .atab')).length > 1) {
await page.focus('#lesson .atab[aria-selected="true"]');
Expand Down
24 changes: 18 additions & 6 deletions scripts/verify/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
lesson's lesson.js — the text a reader copies, not a draft.
3. Runs each approach x language and compares line by line. Ruby, Python and
JavaScript run locally; Go and Rust run in Docker (golang:1.23-alpine,
rust:1-slim), so Docker must be running.
rust:1.98-slim), so Docker must be running.
4. Runs the walkthrough check (steps.mjs) over the same corpus.

A language that could not run is reported as SKIPPED, never as passing.
Expand All @@ -37,21 +37,24 @@
HERE = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.abspath(os.path.join(HERE, '..', '..'))
EXT = {'ruby': 'rb', 'python': 'py', 'javascript': 'js', 'go': 'go', 'rust': 'rs'}
# One approach x language, compile included. A listing that never finishes
# fails here instead of holding the CI job to its 40-minute limit.
TIMEOUT = 20 * 60


def command(lang, work, big_stack=False):
def command(lang, work, big_stack=False, name=None):
if lang == 'ruby':
return ['ruby', f'{work}/main.rb']
if lang == 'python':
return ['python3', f'{work}/main.py']
if lang == 'javascript':
return ['node'] + (['--stack-size=16000'] if big_stack else []) + [f'{work}/main.cjs']
if lang == 'go': # the build cache outlives the container, so the standard library compiles once
return ['docker', 'run', '--rm', '-i', '-v', f'{work}:/w', '-v', 'leetcode-go-build:/root/.cache/go-build',
return ['docker', 'run', '--rm', '-i', '--name', name, '-v', f'{work}:/w', '-v', 'leetcode-go-build:/root/.cache/go-build',
'-w', '/w', 'golang:1.23-alpine',
'sh', '-c', 'go build -o m main.go && ./m']
if lang == 'rust':
return ['docker', 'run', '--rm', '-i', '-v', f'{work}:/w', '-w', '/w', 'rust:1-slim',
return ['docker', 'run', '--rm', '-i', '--name', name, '-v', f'{work}:/w', '-w', '/w', 'rust:1.98-slim',
'sh', '-c', 'rustc -O -o m main.rs 2>&1 >/dev/null | grep -E "^error" ; ./m']


Expand Down Expand Up @@ -123,8 +126,17 @@ def run_one(mode, lang, todo, cases):
main_name = 'main.cjs' if lang == 'javascript' else 'main.' + ext
with open(f'{work}/{main_name}', 'w') as f:
f.write(S.DRIVERS[lang].replace('{SOL}', solution))
r = subprocess.run(command(lang, work, big_stack), input=cases, capture_output=True, text=True, env=env,
preexec_fn=raise_stack if big_stack and lang in ('ruby', 'javascript') else None)
# named, so a container that outlives the timeout can be removed: killing
# the docker client alone leaves it running
name = f'verify-{os.getpid()}-{mode}-{lang}'
try:
r = subprocess.run(command(lang, work, big_stack, name), input=cases, capture_output=True, text=True,
env=env, timeout=TIMEOUT,
preexec_fn=raise_stack if big_stack and lang in ('ruby', 'javascript') else None)
except subprocess.TimeoutExpired:
if lang in ('go', 'rust'):
subprocess.run(['docker', 'rm', '-f', name], capture_output=True)
return True, f'FAIL {mode}/{lang}: still running after {TIMEOUT // 60} minutes'
got = r.stdout.split('\n')
bad = [i for i, (_, e) in enumerate(todo) if i >= len(got) or got[i] != e]
if not bad:
Expand Down
2 changes: 1 addition & 1 deletion src/lessons/3sum/lesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ mountLesson({
// from -3..3, 5,000 of 3–30 from -10..10, and five at n = 3000 — against an
// oracle that counts values and checks pairs of distinct values. Triplets
// are compared in sorted order. The brute force skips the five at n = 3000.
// Go and Rust ran in Docker (golang:1.23-alpine, rust:1-slim).
// Go and Rust ran in Docker (golang:1.23-alpine, rust:1.98-slim).
verification: {
ruby: { brute: 'ran here · 20,008 cases, not the five at n = 3000', pointers: 'ran here · 20,013 cases' },
python: { brute: 'ran here · 20,008 cases, not the five at n = 3000', pointers: 'ran here · 20,013 cases' },
Expand Down
2 changes: 1 addition & 1 deletion src/lessons/basic-calculator/lesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ mountLesson({
// (149,999 nested brackets, nested unary minus, 50,000 numbers, a random
// expression, numbers near 2³¹ − 1, 75,000 "(1)") — against an oracle that
// keeps a stack of bracket signs. Go and Rust ran in Docker
// (golang:1.23-alpine, rust:1-slim); the recursive listing ran with a
// (golang:1.23-alpine, rust:1.98-slim); the recursive listing ran with a
// larger stack in Ruby, Node and Rust. Default-stack limits were measured
// cold, one nested expression per process (Rust: a release build, 8 MB main
// thread).
Expand Down
2 changes: 1 addition & 1 deletion src/lessons/best-time-to-buy-and-sell-stock/lesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ mountLesson({
code: CODE,
// How each language was actually checked, printed as the part 3 badges.
// The corpus: 4 examples, 15,000 short price lists over 0..6, 5,000 up to 10⁴, three of 3,000 — against all-pairs search; the one-pass versions also ran four at n = 10⁵.
// Go and Rust ran in Docker (golang:1.23-alpine, rust:1-slim).
// Go and Rust ran in Docker (golang:1.23-alpine, rust:1.98-slim).
verification: {
ruby: 'ran here · 20,007 cases',
python: 'ran here · 20,007 cases',
Expand Down
2 changes: 1 addition & 1 deletion src/lessons/binary-tree-maximum-path-sum/lesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ mountLesson({
// non-recursive oracle. Trying every node as the top skips those six. Ruby
// and Node ran with a larger stack (BIG_STACK); their default-stack limits
// were measured cold, one chain per process. Go and Rust ran in Docker
// (golang:1.23-alpine, rust:1-slim) on their default stacks.
// (golang:1.23-alpine, rust:1.98-slim) on their default stacks.
verification: {
ruby: { every: 'ran here · 20,007 cases, not the six at 3 × 10⁴; overflows Ruby 3.1\'s default stack past 8,731 deep', once: 'ran here · overflows Ruby 3.1\'s default stack past 8,186 deep' },
python: { every: 'ran here · 20,007 cases, not the six at 3 × 10⁴', once: 'ran here · 20,013 cases, 3 × 10⁴ calls deep' },
Expand Down
2 changes: 1 addition & 1 deletion src/lessons/climbing-stairs/lesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ mountLesson({
// with binomials (itself checked by enumerating every climb up to 20).
// Plain recursion ran on n = 1..35 in every language, and on n = 45, timed
// on an Apple M5 Pro — right answer each time, and the time is the point.
// Go and Rust ran in Docker (golang:1.23-alpine, rust:1-slim).
// Go and Rust ran in Docker (golang:1.23-alpine, rust:1.98-slim).
verification: {
ruby: { naive: 'ran here · n = 1–35, and 45 in 63 s', memo: 'ran here · every n, 1–45', dp: 'ran here · every n, 1–45' },
python: { naive: 'ran here · n = 1–35, and 45 in 72 s', memo: 'ran here · every n, 1–45', dp: 'ran here · every n, 1–45' },
Expand Down
2 changes: 1 addition & 1 deletion src/lessons/coin-change/lesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ mountLesson({
// from 1..10 with amounts 0..12, 5,000 of up to 12 coins with amounts up to
// 500, and five at amount = 10⁴ — against a breadth-first search over the
// amounts. The plain recursion runs only the 15,131 cases with amount ≤ 12.
// Go and Rust ran in Docker (golang:1.23-alpine, rust:1-slim).
// Go and Rust ran in Docker (golang:1.23-alpine, rust:1.98-slim).
verification: {
ruby: { recurse: 'ran here · 15,131 cases, amount ≤ 12 only', table: 'ran here · 20,014 cases' },
python: { recurse: 'ran here · 15,131 cases, amount ≤ 12 only', table: 'ran here · 20,014 cases' },
Expand Down
2 changes: 1 addition & 1 deletion src/lessons/course-schedule/lesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ mountLesson({
// chain closed into a cycle, random DAG and random graph with 5,000 pairs,
// a 2,000-cycle, one course needed by all) — against an oracle that peels
// off free courses until none are left. Go and Rust ran in Docker
// (golang:1.23-alpine, rust:1-slim), every language on its default stack.
// (golang:1.23-alpine, rust:1.98-slim), every language on its default stack.
verification: {
ruby: 'ran here · 20,016 cases',
python: 'ran here · 20,016 cases',
Expand Down
2 changes: 1 addition & 1 deletion src/lessons/diameter-of-binary-tree/lesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ mountLesson({
// all-right and zigzag chains, a random tree, a complete tree, a deep chain
// that forks) — against an oracle that treats the tree as a graph and finds
// the longest shortest path (all pairs, or double BFS when big). Go and Rust
// ran in Docker (golang:1.23-alpine, rust:1-slim).
// ran in Docker (golang:1.23-alpine, rust:1.98-slim).
// Measured cold, one 10⁴ chain per process: Ruby 3.1's default stack
// overflows past 7,705 nodes (brute) and 8,732 (DFS); Node 24's past 6,219
// and 7,773. Both pass all 20,009 cases with a larger stack
Expand Down
2 changes: 1 addition & 1 deletion src/lessons/find-median-from-data-stream/lesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ mountLesson({
// The corpus: the example, 6 edges, 15,000 random runs of up to 20 calls
// over -5..5, 5,000 of up to 500 over ±10⁵, and six of 5 × 10⁴ calls —
// against a Fenwick tree over every value. Go and Rust ran in Docker
// (golang:1.23-alpine, rust:1-slim).
// (golang:1.23-alpine, rust:1.98-slim).
verification: {
ruby: 'ran here · 20,013 cases',
python: 'ran here · 20,013 cases',
Expand Down
2 changes: 1 addition & 1 deletion src/lessons/implement-trie-prefix-tree/lesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ mountLesson({
// over two or three letters, 5,000 of up to 300 calls, and four of 3 × 10⁴
// calls (2,000-letter words, random words, 20,000 prefix queries that miss
// 10,000 words) — against a sorted-list oracle. Go and Rust ran in Docker
// (golang:1.23-alpine, rust:1-slim).
// (golang:1.23-alpine, rust:1.98-slim).
verification: {
ruby: 'ran here · 20,011 cases',
python: 'ran here · 20,011 cases',
Expand Down
2 changes: 1 addition & 1 deletion src/lessons/invert-binary-tree/lesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ mountLesson({
// over -3..3, 5,000 of up to 100 nodes over -100..100, and three 100-node
// chains (all-left, all-right, zigzag) — against a reference that builds a
// new mirrored tree rather than swapping in place. Go and Rust ran in Docker
// (golang:1.23-alpine, rust:1-slim).
// (golang:1.23-alpine, rust:1.98-slim).
verification: {
ruby: 'ran here · 20,010 cases',
python: 'ran here · 20,010 cases',
Expand Down
2 changes: 1 addition & 1 deletion src/lessons/kth-largest-element-in-an-array/lesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ mountLesson({
// The corpus: the 2 examples, 5 edges, 15,000 random arrays of 1–9 values
// from -3..3 with any valid k, 5,000 of up to 300 across ±10⁴, and five at
// n = 10⁵ — against an oracle that counts values and walks down from the
// largest. Go and Rust ran in Docker (golang:1.23-alpine, rust:1-slim).
// largest. Go and Rust ran in Docker (golang:1.23-alpine, rust:1.98-slim).
verification: {
ruby: 'ran here · 20,012 cases',
python: 'ran here · 20,012 cases',
Expand Down
2 changes: 1 addition & 1 deletion src/lessons/largest-rectangle-in-histogram/lesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ mountLesson({
// 12 bars from 0..5, 5,000 of up to 300 across the full range, and five of
// 10⁵ bars — against a nearest-lower-by-jumping oracle. Growing around each
// bar skips the five at 10⁵. Go and Rust ran in Docker (golang:1.23-alpine,
// rust:1-slim).
// rust:1.98-slim).
verification: {
ruby: { extend: 'ran here · 20,008 cases, not the five at n = 10⁵', stack: 'ran here · 20,013 cases' },
python: { extend: 'ran here · 20,008 cases, not the five at n = 10⁵', stack: 'ran here · 20,013 cases' },
Expand Down
2 changes: 1 addition & 1 deletion src/lessons/linked-list-cycle/lesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ mountLesson({
// empty list and repeated values), 15,000 lists up to 8 nodes with every pos,
// 4,990 up to 200 nodes over the full value range, and four at the 10⁴-node
// constraint — each checked against the pos it was built from. Go and Rust
// ran in Docker (golang:1.23-alpine, rust:1-slim); the Rust harness builds
// ran in Docker (golang:1.23-alpine, rust:1.98-slim); the Rust harness builds
// the Rc<RefCell> list the caveat describes.
verification: {
ruby: 'ran here · 20,001 cases up to n = 10⁴',
Expand Down
2 changes: 1 addition & 1 deletion src/lessons/longest-increasing-path-in-a-matrix/lesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ mountLesson({
// reversed, a walled snake 20,099 calls deep, r + c, all equal, a
// checkerboard, random values to 2³¹ − 1) — against an oracle that sorts
// the cells by value. Go and Rust ran in Docker (golang:1.23-alpine,
// rust:1-slim) on their default stacks. The memo DFS limits were measured
// rust:1.98-slim) on their default stacks. The memo DFS limits were measured
// cold, one walled snake per process, on each default stack.
verification: {
ruby: { memo: 'ran here · overflows Ruby 3.1\'s default stack past 2,846 calls deep', peel: 'ran here · 20,016 cases' },
Expand Down
Loading
Loading