Skip to content

Commit c32b32d

Browse files
lufftwclaude
andcommitted
docs(runner): Add Examples Gallery with interpretation guides
Add 5 verified examples with actual output and "How to Interpret" sections: - Multi-solution benchmark (0042 Trapping Rain Water) - Four solutions comparison (0015 3Sum) - Random test generation with seed (0215 Kth Largest) - Memory trace visualization - Complexity estimation (0322 Coin Change) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 54e8df5 commit c32b32d

2 files changed

Lines changed: 172 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ python runner/test_runner.py 0322_coin_change --estimate
8282
Confidence: 1.00
8383
```
8484

85-
> 📖 [More examples →](docs/runner/README.md#complexity-estimation-with-visual-charts)
85+
> 📖 [More examples with interpretation guide ](docs/runner/README.md#examples-gallery)
8686
8787
**Auto-save failing cases for debugging:**
8888

docs/runner/README.md

Lines changed: 171 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,186 @@ python runner/test_runner.py 0023 --all --benchmark
9090
### Random Testing
9191

9292
```bash
93-
python runner/test_runner.py 0004 --generate 10
94-
python runner/test_runner.py 0004 --generate 10 --seed 12345
95-
python runner/test_runner.py 0004 --generate 100 --save-failed
93+
python runner/test_runner.py 0215 --generate 10
94+
python runner/test_runner.py 0215 --generate 10 --seed 12345
95+
python runner/test_runner.py 0215 --generate 100 --save-failed
9696
```
9797

9898
### Complexity Estimation
9999

100100
```bash
101-
python runner/test_runner.py 0004 --estimate
102-
python runner/test_runner.py 0004 --all --estimate
101+
python runner/test_runner.py 0322 --estimate
102+
python runner/test_runner.py 0215 --all --estimate
103103
```
104104

105105
---
106106

107+
## Examples Gallery
108+
109+
This section shows actual output from various test runs to help you understand how to interpret results.
110+
111+
### Example 1: Multi-Solution Benchmark (Trapping Rain Water)
112+
113+
**Command:**
114+
```bash
115+
python runner/test_runner.py 0042_trapping --all --benchmark
116+
```
117+
118+
**Output:**
119+
```
120+
╔═════════════════════════════════════════╗
121+
║ 0042_trapping_rain_water - Performance ║
122+
╠═════════════════════════════════════════╣
123+
║ default: ████████████████████ 106ms ║
124+
║ stack: ███████████████████░ 104ms ║
125+
║ twopointer: ███████████████████░ 102ms ║
126+
║ dp: ██████████████████░░ 100ms ║
127+
╚═════════════════════════════════════════╝
128+
129+
Method Avg Time Pass Rate Complexity Peak RSS
130+
---------- ---------- ---------- -------------------- ----------
131+
default 106.07ms 2/2 O(n) time, O(n) space 4.8MB
132+
stack 103.54ms 2/2 O(n) time, O(n) space 4.7MB
133+
twopointer 102.15ms 2/2 O(n) time, O(1) space 4.6MB
134+
dp 100.35ms 2/2 O(n) time, O(n) space 4.6MB
135+
```
136+
137+
**How to Interpret:**
138+
- Bar length is proportional to execution time (longest = full bar)
139+
- `twopointer` uses O(1) space while others use O(n) — a key insight for interviews
140+
- All approaches are O(n) time but have different constant factors
141+
142+
---
143+
144+
### Example 2: Four Solutions Comparison (3Sum)
145+
146+
**Command:**
147+
```bash
148+
python runner/test_runner.py 0015_3sum --all --benchmark
149+
```
150+
151+
**Output:**
152+
```
153+
╔═══════════════════════════════════════════╗
154+
║ 0015_3sum - Performance ║
155+
╠═══════════════════════════════════════════╣
156+
║ default: ██████████████████░░ 103ms ║
157+
║ two_pointers: ████████████████████ 109ms ║
158+
║ hashset: ██████████████████░░ 102ms ║
159+
║ hash: ██████████████████░░ 102ms ║
160+
╚═══════════════════════════════════════════╝
161+
162+
Method Avg Time Pass Rate Complexity
163+
------------ ---------- ---------- ---------------------------------
164+
default 102.81ms 3/3 O(n²) time, O(1) extra space
165+
two_pointers 108.52ms 3/3 O(n²) time, O(1) extra space
166+
hashset 102.21ms 3/3 O(n²) time, O(n) space for set
167+
hash 102.39ms 3/3 O(n²) time, O(n) space
168+
```
169+
170+
**How to Interpret:**
171+
- All four approaches have similar O(n²) time complexity
172+
- `hashset` and `hash` trade space for simpler deduplication logic
173+
- Similar times indicate the test cases may be small — use `--generate` for stress testing
174+
175+
---
176+
177+
### Example 3: Random Test Generation
178+
179+
**Command:**
180+
```bash
181+
python runner/test_runner.py 0215_kth_largest --generate 5 --seed 42
182+
```
183+
184+
**Output:**
185+
```
186+
🎲 Generator: 5 cases, seed: 42
187+
188+
--- tests/ (static) ---
189+
0215_kth_largest_element_in_an_array_1: ✅ PASS [judge]
190+
0215_kth_largest_element_in_an_array_2: ✅ PASS [judge]
191+
0215_kth_largest_element_in_an_array_3: ✅ PASS [judge]
192+
193+
--- generators/ (5 cases, seed: 42) ---
194+
gen_1: ✅ PASS [generated]
195+
gen_2: ✅ PASS [generated]
196+
gen_3: ✅ PASS [generated]
197+
gen_4: ✅ PASS [generated]
198+
gen_5: ✅ PASS [generated]
199+
200+
Result: 8 / 8 cases passed.
201+
├─ Static: 3/3
202+
└─ Generated: 5/5
203+
```
204+
205+
**How to Interpret:**
206+
- Static tests run first (from `tests/` directory)
207+
- Generated tests use `JUDGE_FUNC` for validation (no expected output file)
208+
- The seed `42` makes tests reproducible — same seed = same test cases
209+
- Use `--save-failed` to capture failing generated cases for debugging
210+
211+
---
212+
213+
### Example 4: Memory Trace Visualization
214+
215+
**Command:**
216+
```bash
217+
python runner/test_runner.py 0042_trapping --memory-trace
218+
```
219+
220+
**Output:**
221+
```
222+
Memory Trace (Run-level RSS)
223+
224+
default:
225+
▁▂▃▃▄▅▆▆▇█
226+
Peak 4.8MB | P95 4.8MB
227+
```
228+
229+
**How to Interpret:**
230+
- Sparkline shows memory usage progression over test cases
231+
- Peak RSS is the maximum memory used across all runs
232+
- P95 RSS is the 95th percentile — useful for identifying outliers
233+
- Compare across methods with `--trace-compare` (requires multiple solutions)
234+
235+
---
236+
237+
### Example 5: Complexity Estimation
238+
239+
**Command:**
240+
```bash
241+
python runner/test_runner.py 0322_coin_change --estimate
242+
```
243+
244+
**Output:**
245+
```
246+
📈 Running complexity estimation...
247+
Mode: Direct call (Mock stdin, no subprocess overhead)
248+
Sizes: [10, 20, 50, 100, 200, 500, 1000, 2000]
249+
Runs per size: 3
250+
n= 100: 0.1286ms (avg of 3 runs)
251+
n= 500: 0.5394ms (avg of 3 runs)
252+
n= 1000: 1.0778ms (avg of 3 runs)
253+
n= 2000: 2.1274ms (avg of 3 runs)
254+
255+
✅ Estimated: O(n)
256+
Confidence: 1.00
257+
Details: Linear: time = 0.038 + 0.001*n (sec)
258+
```
259+
260+
**How to Interpret:**
261+
- Times should roughly double when n doubles for O(n) algorithms
262+
- `Confidence: 1.00` means the curve fit is excellent
263+
- `Details` shows the fitted formula: `time = constant + coefficient * f(n)`
264+
- For this DP problem, n represents the `amount` parameter
265+
266+
**Estimation Accuracy Tips:**
267+
- Works best when algorithm time dominates constant overhead
268+
- Very fast algorithms (< 0.1ms) may show inaccurate results
269+
- If estimated ≠ declared, try larger input sizes via generator
270+
271+
---
272+
107273
## Output Format
108274

109275
### Test Results

0 commit comments

Comments
 (0)