Skip to content

Commit 36be7a9

Browse files
committed
docs: update docs
1 parent 68db0be commit 36be7a9

File tree

2 files changed

+224
-8
lines changed

2 files changed

+224
-8
lines changed
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
# Batch Problem Creation Command
2+
3+
## Assistant Workflow
4+
5+
When user requests **batch creation of multiple problems**, the assistant will:
6+
7+
1. **Get count from user** (default: 5 problems)
8+
2. **Loop through each problem** following the complete workflow
9+
3. **For each problem**:
10+
- Find next problem via `poetry run python .cursor/.dev/next_problem.py`
11+
- Follow all steps from `.cursor/commands/problem-creation.md`
12+
- Verify reproducibility and quality via `.cursor/commands/test-quality-assurance.md`
13+
4. **Provide batch summary** at the end
14+
15+
## High-Level Process
16+
17+
### Step 1: Initialize Batch
18+
19+
- Ask user for count (default: 5)
20+
- Confirm batch creation parameters
21+
- Set up progress tracking
22+
23+
### Step 2: Problem Creation Loop
24+
25+
For each problem (1 to count):
26+
27+
#### 2.1: Find Next Problem
28+
29+
```bash
30+
poetry run python .cursor/.dev/next_problem.py
31+
```
32+
33+
- Extract problem number and name from output
34+
- Log progress: "Problem X/Count: #NUMBER - NAME"
35+
36+
#### 2.2: Follow Problem Creation Workflow
37+
38+
Execute complete workflow from `.cursor/commands/problem-creation.md`:
39+
40+
1. **Scrape** problem data using `poetry run lcpy scrape`
41+
2. **Transform** data into proper JSON template format
42+
3. **Include images** - Extract image URLs and add to readme_examples
43+
4. **Create** JSON file in `leetcode_py/cli/resources/leetcode/json/problems/{problem_name}.json`
44+
5. **Update** Makefile with `PROBLEM ?= {problem_name}`
45+
6. **Generate** problem structure using `make p-gen`
46+
7. **Verify** with `make p-lint` and fix template issues
47+
8. **Iterate** if needed: re-run `make p-gen PROBLEM={problem_name} FORCE=1` and `make p-lint`
48+
49+
#### 2.3: Implement Optimal Solution
50+
51+
**CRITICAL**: Before running quality assurance, implement the optimal solution:
52+
53+
1. **Implement solution**: Write the optimal algorithm in `solution.py`
54+
2. **Add multiple approaches**: Include alternative solutions (e.g., Solution, SolutionOptimized)
55+
3. **Use parametrized testing**: Ensure all solution approaches are tested
56+
4. **Verify correctness**: Solution must handle all test cases correctly
57+
58+
#### 2.4: Quality Assurance
59+
60+
Execute workflow from `.cursor/commands/test-quality-assurance.md`:
61+
62+
1. **Run tests**: `make p-test PROBLEM={problem_name}`
63+
2. **Check test coverage**: Ensure minimum 12 test cases
64+
3. **Enhance if needed**: Update JSON with more test cases
65+
4. **Verify reproducibility**: Ensure all tests pass consistently
66+
5. **Final verification**: `make p-lint PROBLEM={problem_name}`
67+
68+
### Step 3: Batch Summary
69+
70+
Provide comprehensive summary:
71+
72+
- Total problems created
73+
- Success rate
74+
- Failed problems (if any) with reasons
75+
- Time taken
76+
- Next steps for any failures
77+
78+
## Example Assistant Response
79+
80+
```
81+
I'll help you create 5 problems in batch. Let me start the process:
82+
83+
=== Batch Problem Creation Started ===
84+
Creating 5 problems...
85+
86+
=== Problem 1/5 ===
87+
Finding next problem...
88+
Running: poetry run python .cursor/.dev/next_problem.py
89+
Next problem: Problem #123 - Word Ladder
90+
Processing: #123 - Word Ladder
91+
92+
Following problem creation workflow:
93+
1. Scraping problem data...
94+
Running: poetry run lcpy scrape -n 123
95+
✓ Scraped successfully
96+
97+
2. Creating JSON template...
98+
✓ JSON template created with images included
99+
✓ Saved to leetcode_py/cli/resources/leetcode/json/problems/word_ladder.json
100+
101+
3. Updating Makefile...
102+
✓ Updated PROBLEM ?= word_ladder
103+
104+
4. Generating problem structure...
105+
Running: make p-gen PROBLEM=word_ladder
106+
✓ Problem structure generated
107+
108+
5. Verifying with linting...
109+
Running: make p-lint PROBLEM=word_ladder
110+
✓ Linting passed
111+
112+
6. Implementing optimal solution...
113+
✓ Solution implemented with multiple approaches
114+
✓ Parametrized testing configured
115+
116+
7. Running quality assurance...
117+
Running: make p-test PROBLEM=word_ladder
118+
✓ Tests passed (15 test cases)
119+
✓ Quality assurance completed
120+
121+
=== Problem 2/5 ===
122+
[Continue with same process...]
123+
124+
=== Batch Summary ===
125+
Total Problems Created: 5/5
126+
Success Rate: 100%
127+
Failed Problems: None
128+
Time Taken: 12 minutes
129+
Next Steps: All problems created successfully!
130+
131+
=== Batch Problem Creation Completed ===
132+
```
133+
134+
## Error Handling
135+
136+
### If a problem fails:
137+
138+
1. **Log the failure** with specific reason
139+
2. **Continue with next problem** (don't stop the batch)
140+
3. **Add to retry list** for manual intervention later
141+
4. **Update success rate** accordingly
142+
143+
### Common failure scenarios:
144+
145+
- Scraping fails (problem not found)
146+
- JSON template issues (invalid syntax)
147+
- Generation fails (missing dependencies)
148+
- Tests fail (incorrect expected values)
149+
- Linting errors (template problems)
150+
151+
### Recovery actions:
152+
153+
- **Scraping**: Try alternative parameters or manual data entry
154+
- **JSON**: Fix syntax and regenerate
155+
- **Generation**: Check Makefile and dependencies
156+
- **Tests**: Update expected values in JSON template
157+
- **Linting**: Fix template issues and regenerate
158+
159+
## Success Criteria
160+
161+
Each problem must meet:
162+
163+
- ✅ All files generated (README.md, solution.py, test_solution.py, helpers.py, playground.ipynb, **init**.py)
164+
-**Optimal solution implemented** with correct algorithm
165+
-**Multiple solution approaches** (e.g., Solution, SolutionOptimized)
166+
-**Parametrized testing** for all solution approaches
167+
- ✅ Linting passes without errors
168+
- ✅ All tests pass
169+
- ✅ Minimum 12 comprehensive test cases
170+
- ✅ Images included in README if available
171+
- ✅ Proper JSON template created
172+
- ✅ Code coverage includes edge cases
173+
174+
## Batch Parameters
175+
176+
- **Count**: Number of problems to create (default: 5)
177+
- **Tags**: Optional filter for specific problem lists
178+
- **Force**: Whether to overwrite existing problems
179+
- **Dry Run**: Preview mode without actual creation
180+
181+
## Notes
182+
183+
- **Sequential Processing**: Create one problem at a time to avoid conflicts
184+
- **Progress Tracking**: Show clear progress indicators
185+
- **Error Recovery**: Continue batch even if individual problems fail
186+
- **Solution Implementation**: **MUST** implement optimal solution before quality assurance
187+
- **Quality Focus**: Ensure each problem meets all quality standards
188+
- **Reproducibility**: Verify tests pass consistently with implemented solutions
189+
- **Documentation**: Maintain clear logs of the entire process

.cursor/commands/problem-creation.md

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ Required fields for `leetcode_py/cli/resources/leetcode/json/problems/{problem_n
5050
- `playground_assertion`: Use single quotes for string literals
5151
- Double quotes in JSON + cookiecutter + Jupyter notebook = triple escaping issues
5252

53+
**Test Cases Format:**
54+
55+
- `test_cases`: Use structured format with `{"list": ["..."]}` instead of string arrays
56+
- Each test case should be a string representation of the tuple/parameters
57+
- Example: `{"list": ["('input1', 'input2', expected)", "('input3', 'input4', expected)"]}`
58+
5359
**IMPORTANT: Create actual JSON files, not JSON5**
5460

5561
The template below uses JSON5 format with comments for documentation purposes only. When creating the actual `.json` file, you must:
@@ -183,9 +189,30 @@ The template below uses JSON5 format with comments for documentation purposes on
183189
parametrize: "s, t, expected", // pytest parametrize parameters
184190
// For tree: "root_list, expected_list"
185191
// For design: "operations, inputs, expected"
186-
test_cases: "[('anagram', 'nagaram', True), ('rat', 'car', False), ('listen', 'silent', True), ('hello', 'bello', False), ('', '', True), ('a', 'a', True), ('a', 'b', False), ('ab', 'ba', True), ('abc', 'bca', True), ('abc', 'def', False), ('aab', 'abb', False), ('aabbcc', 'abcabc', True), ('abcd', 'abcde', False), ('race', 'care', True), ('elbow', 'below', True), ('study', 'dusty', True), ('night', 'thing', True), ('stressed', 'desserts', True)]",
187-
// For tree: "[([4, 2, 7, 1, 3, 6, 9], [4, 7, 2, 9, 6, 3, 1]), ([2, 1, 3], [2, 3, 1]), ([], [])]"
188-
// For design: "[(['LRUCache', 'put', 'get'], [[2], [1, 1], [1]], [None, None, 1])]"
192+
test_cases: {
193+
list: [
194+
"('anagram', 'nagaram', True)",
195+
"('rat', 'car', False)",
196+
"('listen', 'silent', True)",
197+
"('hello', 'bello', False)",
198+
"('', '', True)",
199+
"('a', 'a', True)",
200+
"('a', 'b', False)",
201+
"('ab', 'ba', True)",
202+
"('abc', 'bca', True)",
203+
"('abc', 'def', False)",
204+
"('aab', 'abb', False)",
205+
"('aabbcc', 'abcabc', True)",
206+
"('abcd', 'abcde', False)",
207+
"('race', 'care', True)",
208+
"('elbow', 'below', True)",
209+
"('study', 'dusty', True)",
210+
"('night', 'thing', True)",
211+
"('stressed', 'desserts', True)",
212+
],
213+
},
214+
// For tree: {"list": ["([4, 2, 7, 1, 3, 6, 9], [4, 7, 2, 9, 6, 3, 1])", "([2, 1, 3], [2, 3, 1])", "([], [])"]}
215+
// For design: {"list": ["(['LRUCache', 'put', 'get'], [[2], [1, 1], [1]], [None, None, 1])"]}
189216
body: " result = run_is_anagram(Solution, s, t)\n assert_is_anagram(result, expected)",
190217
// For tree: " result = run_invert_tree(Solution, root_list)\n assert_invert_tree(result, expected_list)"
191218
// For design: " result, _ = run_lru_cache(LRUCache, operations, inputs)\n assert_lru_cache(result, expected)"
@@ -218,29 +245,29 @@ The template below uses JSON5 format with comments for documentation purposes on
218245
// - solution_class_name: "Solution"
219246
// - solution_imports: ""
220247
// - Simple method signatures: "(self, s: str, t: str) -> bool"
221-
// - Basic test cases: string/number parameters
248+
// - Basic test cases: structured format with {"list": ["..."]}
222249
// - Playground: single quotes for strings
223250
//
224251
// TREE PROBLEMS (invert_binary_tree):
225252
// - solution_class_name: "Solution"
226253
// - solution_imports: "from leetcode_py import TreeNode"
227254
// - Tree method signatures: "(self, root: TreeNode[int] | None) -> TreeNode[int] | None"
228255
// - Helper functions use TreeNode.from_list()
229-
// - Test cases: list representations of trees
256+
// - Test cases: structured format with list representations of trees
230257
// - Playground: TreeNode imports and list conversions
231258
//
232259
// LINKED LIST PROBLEMS (merge_two_sorted_lists):
233260
// - solution_class_name: "Solution"
234261
// - solution_imports: "from leetcode_py import ListNode"
235262
// - List method signatures: "(self, list1: ListNode[int] | None, list2: ListNode[int] | None) -> ListNode[int] | None"
236263
// - Helper functions use ListNode.from_list()
237-
// - Test cases: list representations of linked lists
264+
// - Test cases: structured format with list representations of linked lists
238265
// - Playground: ListNode imports and list conversions
239266
//
240267
// DESIGN PROBLEMS (lru_cache):
241268
// - solution_class_name: "LRUCache" (custom class name)
242269
// - Multiple methods including __init__
243-
// - Operations-based testing: operations, inputs, expected arrays
270+
// - Operations-based testing: structured format with operations, inputs, expected arrays
244271
// - Complex test body with operation loops
245272
// - Helper functions return (results, instance) for debugging
246273
// - Playground: print results, return instance
@@ -250,7 +277,7 @@ The template below uses JSON5 format with comments for documentation purposes on
250277
// - solution_class_name: "Trie(DictTree[str])" (with inheritance)
251278
// - solution_imports: "from leetcode_py.data_structures import DictTree, RecursiveDict"
252279
// - Custom class with inheritance from DictTree
253-
// - Operations-based testing like design problems
280+
// - Operations-based testing with structured format like design problems
254281
// - Helper functions return (results, instance) for debugging
255282
//
256283
// MULTIPLE SOLUTIONS (invert_binary_tree, lru_cache):

0 commit comments

Comments
 (0)