Skip to content

Commit ef1a429

Browse files
committed
docs: add llm-assisted-problem-creation.md
1 parent 4a5c370 commit ef1a429

File tree

15 files changed

+358
-3
lines changed

15 files changed

+358
-3
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PYTHON_VERSION = 3.13
2-
PROBLEM ?= daily_temperatures
2+
PROBLEM ?= house_robber
33
FORCE ?= 0
44
COMMA := ,
55

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,11 @@ make gen-all-problems
187187

188188
### LLM-Assisted Problem Creation
189189

190-
To extend the problem collection beyond the current catalog, leverage an LLM assistant within your IDE (Cursor, GitHub Copilot Chat, Amazon Q, etc.):
190+
To extend the problem collection beyond the current catalog, leverage an LLM assistant within your IDE (Cursor, GitHub Copilot Chat, Amazon Q, etc.).
191+
192+
📖 **[Complete LLM-Assisted Problem Creation Guide](docs/llm-assisted-problem-creation.md)** - Comprehensive guide with screenshots and detailed workflow.
193+
194+
**Quick Start:**
191195

192196
```bash
193197
# Problem generation commands:
@@ -240,6 +244,8 @@ poetry run python -m leetcode_py.tools.check_test_cases --threshold=10
240244

241245
### CLI Commands (Global)
242246

247+
📖 **[Complete CLI Usage Guide](docs/cli-usage.md)** - Detailed documentation with all options and examples.
248+
243249
```bash
244250
# Generate problems
245251
lcpy gen -n 1 # Single problem by number

docs/images/generated-solution.png

57 KB
Loading

docs/images/generated-test.png

203 KB
Loading
121 KB
Loading
82.2 KB
Loading
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# LLM-Assisted Problem Creation Guide
2+
3+
This guide demonstrates how to leverage Large Language Models (LLMs) like Amazon Q, GitHub Copilot Chat, or Cursor to automatically generate new LeetCode problems for your practice environment.
4+
5+
## Overview
6+
7+
The LLM-assisted workflow enables you to add new problems to your collection with a simple natural language command. The AI assistant handles the entire process from scraping problem data to generating the complete problem structure with comprehensive test cases.
8+
9+
## Prerequisites
10+
11+
### Required LLM Context
12+
13+
For optimal results, include these rule files in your LLM context:
14+
15+
- [`.amazonq/rules/problem-creation.md`](../.amazonq/rules/problem-creation.md) - Complete problem generation workflow
16+
- [`.amazonq/rules/test-quality-assurance.md`](../.amazonq/rules/test-quality-assurance.md) - Test enhancement and reproducibility verification
17+
- [`.amazonq/rules/development-rules.md`](../.amazonq/rules/development-rules.md) - Code standards and testing patterns
18+
19+
### Setup Your IDE
20+
21+
Configure your IDE with an LLM assistant:
22+
23+
- **Amazon Q**: Install the Amazon Q plugin
24+
- **GitHub Copilot**: Enable Copilot Chat
25+
- **Cursor**: Built-in AI assistant
26+
- **Other**: Any IDE with LLM integration
27+
28+
## Quick Start
29+
30+
### Basic Problem Addition
31+
32+
Simply ask your LLM assistant to add a problem:
33+
34+
![Prompt with Context](images/prompt-with-context.png)
35+
36+
_Example prompt showing how to request a new problem with the LLM assistant_
37+
38+
```bash
39+
# Simple commands that work:
40+
"Add problem 198. House Robber"
41+
"Add problem 198. House Robber. tag: grind"
42+
"Create problem 70. Climbing Stairs with grind-75 tag"
43+
```
44+
45+
### What Happens Automatically
46+
47+
The LLM assistant will execute the complete workflow:
48+
49+
1. **Scrape** problem data from LeetCode
50+
2. **Transform** data into proper JSON template format (including images)
51+
3. **Create** JSON file in `leetcode_py/cli/resources/leetcode/json/problems/{problem_name}.json`
52+
4. **Update** `leetcode_py/cli/resources/leetcode/json/tags.json5` with specified tags
53+
5. **Generate** complete problem structure in `leetcode/{problem_name}/`
54+
6. **Verify** with linting checks (iterates from step 3 until all pass)
55+
56+
![Problems Are Generated](images/problems-are-generated.png)
57+
58+
_Source control view showing all files created and modified during the problem generation process_
59+
60+
## Generated Problem Structure
61+
62+
### Solution Template
63+
64+
The assistant generates a clean solution template with proper type hints:
65+
66+
![Generated Solution](images/generated-solution.png)
67+
68+
_Generated solution.py file with TODO placeholder and proper method signature_
69+
70+
### Comprehensive Test Suite
71+
72+
Each problem includes 10+ test cases covering edge cases (note: generated test cases may need verification for correctness):
73+
74+
![Generated Test](images/generated-test.png)
75+
76+
_Generated test_solution.py with parametrized tests and comprehensive test cases_
77+
78+
## Test Enhancement Workflow
79+
80+
### Enhancing Existing Problems
81+
82+
Improve test coverage for existing problems:
83+
84+
```bash
85+
"Enhance test cases for two_sum problem"
86+
"Add more edge cases to binary_tree_inorder_traversal"
87+
"Fix test reproducibility for valid_palindrome"
88+
```
89+
90+
### Quality Assurance
91+
92+
The assistant can identify problems needing more test cases and verify test case correctness and reproducibility:
93+
94+
```bash
95+
"Check which problems need more test cases"
96+
"Find problems with less than 12 test cases"
97+
"Verify test case correctness for house_robber"
98+
"Fix test reproducibility for binary_tree_inorder_traversal"
99+
```
100+
101+
## Best Practices
102+
103+
### Effective Prompts
104+
105+
**Good prompts:**
106+
107+
- "Add problem 198. House Robber with grind tag"
108+
- "Create problem 70. Climbing Stairs for grind-75"
109+
- "Enhance test cases for two_sum problem"
110+
111+
**Avoid:**
112+
113+
- Vague requests without problem numbers
114+
- Requests for non-existent problems
115+
116+
## Troubleshooting
117+
118+
### Common Issues
119+
120+
**Template errors:**
121+
122+
- Assistant will automatically fix JSON template issues
123+
- Re-runs generation until linting passes
124+
- If JSON template fails after many iterations, ask agent to review the example template carefully as mentioned in the rules
125+
126+
**Test failures:**
127+
128+
- Assistant verifies test cases against expected outputs
129+
- Fixes incorrect expected values
130+
- Use test QA workflow for comprehensive test enhancement and reproducibility verification
131+
132+
## Integration with Development Workflow
133+
134+
### CI/CD Compatibility
135+
136+
Generated problems integrate seamlessly with:
137+
138+
- **Test Reproducibility** - CI automatically verifies problems can be regenerated consistently; just implement your solution and CI handles the rest
139+
140+
## Conclusion
141+
142+
LLM-assisted problem creation transforms the tedious process of adding new problems into a simple natural language interaction. The assistant handles all the complexity while ensuring professional code quality and comprehensive test coverage.
143+
144+
Start practicing with your new problems immediately - the assistant takes care of everything else!

leetcode/house_robber/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# House Robber
2+
3+
**Difficulty:** Medium
4+
**Topics:** Array, Dynamic Programming
5+
**Tags:** grind
6+
7+
**LeetCode:** [Problem 198](https://leetcode.com/problems/house-robber/description/)
8+
9+
## Problem Description
10+
11+
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and **it will automatically contact the police if two adjacent houses were broken into on the same night**.
12+
13+
Given an integer array `nums` representing the amount of money of each house, return \*the maximum amount of money you can rob tonight **without alerting the police\***.
14+
15+
## Examples
16+
17+
### Example 1:
18+
19+
```
20+
Input: nums = [1,2,3,1]
21+
Output: 4
22+
Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).
23+
Total amount you can rob = 1 + 3 = 4.
24+
```
25+
26+
### Example 2:
27+
28+
```
29+
Input: nums = [2,7,9,3,1]
30+
Output: 12
31+
Explanation: Rob house 1 (money = 2), rob house 3 (money = 9) and rob house 5 (money = 1).
32+
Total amount you can rob = 2 + 9 + 1 = 12.
33+
```
34+
35+
## Constraints
36+
37+
- `1 <= nums.length <= 100`
38+
- `0 <= nums[i] <= 400`

leetcode/house_robber/__init__.py

Whitespace-only changes.

leetcode/house_robber/helpers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def run_rob(solution_class: type, nums: list[int]):
2+
implementation = solution_class()
3+
return implementation.rob(nums)
4+
5+
6+
def assert_rob(result: int, expected: int) -> bool:
7+
assert result == expected
8+
return True

0 commit comments

Comments
 (0)