Compare commits

..
9 changed files with 361 additions and 12 deletions

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
#!/bin/sh
# Pre-push: the docs pages under apps/docs/content are generated from work/1
# by `bun run sync`, and deploy.yml publishes whatever main holds. Regenerate
# them now and refuse the push if the result differs from the tree, so a
# solution never lands without its page (or with a stale `## Solution`).
#
# Bypass for a deliberate partial push: git push --no-verify
set -eu
cd "$(git rev-parse --show-toplevel)"
report=$(bun run --silent sync)
changed=$(git status --porcelain -- apps/docs/content)
if [ -n "$changed" ]; then
printf '%s\n' "$report" | grep -v 'skipped (in sync)' >&2
printf '\npre-push: apps/docs/content is out of sync with work/1 — commit the regenerated pages:\n%s\n' "$changed" >&2
exit 1
fi
+1
View File
@@ -47,6 +47,7 @@ flowchart LR
| `apps/docs/` | Blume site (`blume.config.ts`, `content/`, `islands/`, `public/`). `content/<topic>/<num>-<slug>.mdx` plus one `meta.ts` per topic folder, all generated by sync: the folder is the README campaign topic slug (`tree-dfs/`, `heap-priority-queue/`) and a real route segment (`/tree-dfs/invert-binary-tree`), the `meta.ts` carries the exact label and topic number so the sidebar reads in curriculum order, and the page badge is the `work/` data-structure category. A hand-written `<topic>/index.mdx` (`hidden: true`) is that topic's landing page: Blume ≥ 1.7.3 links the sidebar group row to it (`sliding-window/index.mdx` → `/sliding-window`) and the hidden flag drops the duplicate row |
| `apps/api/` | Cloudflare Worker workspace: `src/` modules, `data/schedule.json` (the plan: `date → { topics | problems | gate | sweep }`, human-edited, bundled at deploy), `migrations/` (append-only; `0002` is the +3/+7 ladder rebuild) |
| `.github/workflows/` | deploy (docs → Pages, Worker → Cloudflare, on every main push), close-solved (issues + `/admin/solved` + Project `Set`/`Difficulty`, needs `SRS_ADMIN_KEY` and `PROJECT_PAT`), close-topics, sync-d1 (issue edits → `/admin/reconcile`), spaced-repetition (daily 06:00 ET cron → today's review issue; `GITHUB_TOKEN` only, no secrets) |
| `.githooks/` | Tracked git hooks; `bun install` points `core.hooksPath` here (root `prepare` script, no husky). `pre-push` runs `bun run sync` and refuses the push while `apps/docs/content` differs from the tree, so a solution never reaches `main` (and `deploy.yml`) without its page. `git push --no-verify` for a deliberate partial push |
## Development Commands
+13 -12
View File
@@ -6,24 +6,25 @@
<a href="https://x.com/basedprad"><img alt="follow" src="https://shieldcn.dev/x/follow/basedprad.svg" /></a>
<a href="https://leetcode.com/progress"><img alt="Custom badge" src="https://shieldcn.dev/badge/view-@prdlk.svg?logo=leetcode" /></a>
<a href="https://lc.prad.nu"><img alt="badge" src="https://shieldcn.dev/badge/Read-Documentation.svg?logo=lu%3ABook" /></a>
<a href="https://lc.prad.nu/progress"><img alt="gate pass rate" src="https://srs-api.prdlk.workers.dev/badge/gate.svg" /></a>
</p>
<p align="center">
<sub>8-week interview-prep fight camp. Each phase is a milestone; each topic an issue; each problem a sub-issue.<br>
Charts are live from the SRS Worker — the daily digest email drives the schedule.</sub>
New topic Mon–Fri, gate on Saturday, Sunday off — every solve comes back at <strong>+3</strong> and <strong>+7</strong> days,
the two windows that keep the rest day clear (a Thursday solve's +3 slides to Monday).<br>
Charts are live from the SRS Worker, never committed: pushing a solution or tapping the daily digest moves them within ~5 min.</sub>
</p>
<p align="center">
<img alt="phase progress" src="https://shieldcn.dev/chart/npm/zod.svg" />
</p>
<p align="center">
<img alt="SRS ladder" src="https://shieldcn.dev/chart/npm/zod.svg" />
</p>
<p align="center">
<img alt="attempt heatmap" src="https://shieldcn.dev/chart/npm/zod.svg" />
</p>
<table align="center">
<tr>
<td colspan="2" align="center"><img alt="phase progress" width="100%" src="https://srs-api.prdlk.workers.dev/chart/progress.svg" /></td>
</tr>
<tr>
<td align="center" width="53%"><img alt="SRS ladder — new / +3 / +7 / retired" width="100%" src="https://srs-api.prdlk.workers.dev/chart/ladder.svg" /></td>
<td align="center" width="47%"><img alt="attempt heatmap" width="100%" src="https://srs-api.prdlk.workers.dev/chart/heatmap.svg" /></td>
</tr>
</table>
## Phase I — Linear Structures · Weeks 1–2
@@ -0,0 +1,67 @@
---
title: '127. Word Ladder'
description: 'A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that:'
sidebar:
label: 'Word Ladder'
badge: 'Hard'
---
<Badge variant="accent">Hash Table</Badge>
### Example 1:
- Input: `beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"]`
- Output: `5`
- Explanation: One shortest transformation sequence is "hit" -> "hot" -> "dot" -> "dog" -> cog", which is `5` words long.
### Example 2:
- Input: `beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log"]`
- Output: `0`
- Explanation: The `endWord` "cog" is not in `wordList`, therefore there is no valid transformation sequence.
### Constraints:
- `1 <= beginWord.length <= 10`
- `endWord.length == beginWord.length`
- `1 <= wordList.length <= 5000`
- `wordList[i].length == beginWord.length`
- `beginWord`, `endWord`, and `wordList[i]` consist of lowercase English letters.
- `beginWord != endWord`
- All the words in `wordList` are unique.
## Solution
```py
import collections
class Solution:
def ladderLength(self, beginWord: str, endWord: str, wordList: list[str]) -> int:
if endWord not in wordList:
return 0
adj = collections.defaultdict(list)
wordList.append(beginWord)
for word in wordList:
for j in range(len(word)):
pattern = word[:j] + "*" + word[j + 1 :]
adj[pattern].append(word)
visit = set([beginWord])
q = collections.deque([beginWord])
res = 1
while q:
for i in range(len(q)):
word = q.popleft()
if word == endWord:
return res
for j in range(len(word)):
pattern = word[:j] + "*" + word[j + 1 :]
for adjWord in adj[pattern]:
if adjWord not in visit:
visit.add(adjWord)
q.append(adjWord)
res += 1
return 0
```
@@ -0,0 +1,72 @@
---
title: '994. Rotting Oranges'
description: 'You are given an m x n grid where each cell can have one of three values:'
sidebar:
label: 'Rotting Oranges'
badge: 'Medium'
---
<Badge variant="accent">Array</Badge>
### Example 1:
- Input: `grid = [[2,1,1],[1,1,0],[0,1,1]]`
- Output: `4`
### Example 2:
- Input: `grid = [[2,1,1],[0,1,1],[1,0,1]]`
- Output: `-1`
- Explanation: The orange in the bottom left corner (row `2`, column `0`) is never rotten, because rotting only happens 4-directionally.
### Example 3:
- Input: `grid = [[0,2]]`
- Output: `0`
- Explanation: Since there are already no fresh oranges at minute `0`, the answer is just `0`.
### Constraints:
- `m == grid.length`
- `n == grid[i].length`
- `1 <= m, n <= 10`
- grid[i][j] is 0, 1, or 2.
## Solution
```py
from collections import deque
class Solution:
def orangesRotting(self, grid: list[list[int]]) -> int:
q = deque()
time, fresh = 0, 0
rows, cols = len(grid), len(grid[0])
for r in range(rows):
for c in range(cols):
if grid[r][c] == 1:
fresh += 1
if grid[r][c] == 2:
q.append([r, c])
directions = [[0, 1], [0, -1], [1, 0], [-1, 0]]
while q and fresh > 0:
for i in range(len(q)):
r, c = q.popleft()
for dr, dc in directions:
row, col = dr + r, dc + c
# check if in bounds
if (
row < 0
or col < 0
or row == len(grid)
or col == len(grid[0])
or grid[row][col] != 1
):
continue
grid[row][col] = 2
q.append([row, col])
fresh -= 1
time += 1
return time if fresh == 0 else -1
```
+3
View File
@@ -0,0 +1,3 @@
import { defineMeta } from "blume";
export default defineMeta({ title: "Graph BFS", order: 17 });
+1
View File
@@ -4,6 +4,7 @@
"type": "module",
"workspaces": ["apps/*"],
"scripts": {
"prepare": "git config core.hooksPath .githooks",
"dev": "cd apps/docs && bun run dev",
"build": "cd apps/docs && bun run build",
"doctor": "cd apps/docs && bun run doctor",
+93
View File
@@ -0,0 +1,93 @@
"""
127. Word Ladder
Difficulty: Hard
https://leetcode.com/problems/word-ladder/
──────────────────────────────────────────────────
A transformation sequence from word beginWord to word endWord using a
dictionary wordList is a sequence of words beginWord -> s1 -> s2 ->
... -> sk such that:
• Every adjacent pair of words differs by a single letter.
• Every si for 1 <= i <= k is in wordList. Note that beginWord does
not need to be in wordList.
• sk == endWord
Given two words, beginWord and endWord, and a dictionary wordList,
return the number of words in the shortest transformation sequence
from beginWord to endWord, or 0 if no such sequence exists.
Example 1:
Input: beginWord = "hit", endWord = "cog", wordList =
["hot","dot","dog","lot","log","cog"]
Output: 5
Explanation: One shortest transformation sequence is "hit" -> "hot"
-> "dot" -> "dog" -> cog", which is 5 words long.
Example 2:
Input: beginWord = "hit", endWord = "cog", wordList =
["hot","dot","dog","lot","log"]
Output: 0
Explanation: The endWord "cog" is not in wordList, therefore there is
no valid transformation sequence.
Constraints:
• 1 <= beginWord.length <= 10
• endWord.length == beginWord.length
• 1 <= wordList.length <= 5000
• wordList[i].length == beginWord.length
• beginWord, endWord, and wordList[i] consist of lowercase English
letters.
• beginWord != endWord
• All the words in wordList are unique.
"""
import collections
class Solution:
def ladderLength(self, beginWord: str, endWord: str, wordList: list[str]) -> int:
if endWord not in wordList:
return 0
adj = collections.defaultdict(list)
wordList.append(beginWord)
for word in wordList:
for j in range(len(word)):
pattern = word[:j] + "*" + word[j + 1 :]
adj[pattern].append(word)
visit = set([beginWord])
q = collections.deque([beginWord])
res = 1
while q:
for i in range(len(q)):
word = q.popleft()
if word == endWord:
return res
for j in range(len(word)):
pattern = word[:j] + "*" + word[j + 1 :]
for adjWord in adj[pattern]:
if adjWord not in visit:
visit.add(adjWord)
q.append(adjWord)
res += 1
return 0
@@ -0,0 +1,93 @@
"""
994. Rotting Oranges
Difficulty: Medium
https://leetcode.com/problems/rotting-oranges/
──────────────────────────────────────────────────
You are given an m x n grid where each cell can have one of three
values:
• 0 representing an empty cell,
• 1 representing a fresh orange, or
• 2 representing a rotten orange.
Every minute, any fresh orange that is 4-directionally adjacent to a
rotten orange becomes rotten.
Return the minimum number of minutes that must elapse until no cell
has a fresh orange. If this is impossible, return -1.
Example 1:
Input: grid = [[2,1,1],[1,1,0],[0,1,1]]
Output: 4
Example 2:
Input: grid = [[2,1,1],[0,1,1],[1,0,1]]
Output: -1
Explanation: The orange in the bottom left corner (row 2, column 0)
is never rotten, because rotting only happens 4-directionally.
Example 3:
Input: grid = [[0,2]]
Output: 0
Explanation: Since there are already no fresh oranges at minute 0,
the answer is just 0.
Constraints:
• m == grid.length
• n == grid[i].length
• 1 <= m, n <= 10
• grid[i][j] is 0, 1, or 2.
"""
from collections import deque
class Solution:
def orangesRotting(self, grid: list[list[int]]) -> int:
q = deque()
time, fresh = 0, 0
rows, cols = len(grid), len(grid[0])
for r in range(rows):
for c in range(cols):
if grid[r][c] == 1:
fresh += 1
if grid[r][c] == 2:
q.append([r, c])
directions = [[0, 1], [0, -1], [1, 0], [-1, 0]]
while q and fresh > 0:
for i in range(len(q)):
r, c = q.popleft()
for dr, dc in directions:
row, col = dr + r, dc + c
# check if in bounds
if (
row < 0
or col < 0
or row == len(grid)
or col == len(grid[0])
or grid[row][col] != 1
):
continue
grid[row][col] = 2
q.append([row, col])
fresh -= 1
time += 1
return time if fresh == 0 else -1