Skip to content

Commit 1ef67fa

Browse files
committed
feat: implemented cookiecutter template
1 parent fda86af commit 1ef67fa

31 files changed

+464
-256
lines changed

.templates/leetcode/.example/examples/basic.json5

Lines changed: 0 additions & 53 deletions
This file was deleted.

.templates/leetcode/.example/examples/tree.json5

Lines changed: 0 additions & 51 deletions
This file was deleted.

.templates/leetcode/.example/{{cookiecutter.question_name}}/solution.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

.templates/leetcode/.prompt/invert_binary_tree.md

Lines changed: 0 additions & 54 deletions
This file was deleted.

.templates/leetcode/.prompt/reverse_linked_list_ii.md

Lines changed: 0 additions & 49 deletions
This file was deleted.

.templates/leetcode/.example/cookiecutter.json renamed to .templates/leetcode/cookiecutter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"constraints": "- 2 <= nums.length <= 10^4\n- -10^9 <= nums[i] <= 10^9\n- -10^9 <= target <= 10^9\n- Only one valid answer exists.",
1919
"parameters": "nums: list[int], target: int",
2020
"return_type": "list[int]",
21+
"dummy_return": "[]",
2122
"imports": "",
2223
"test_setup": "",
2324
"test_logging": "",
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# LeetCode Problem Template Examples
2+
3+
These JSON5 files serve as reference templates for creating new LeetCode problems. Each template is designed to help LLMs parse raw problem text from leetcode.com into the correct JSON format.
4+
5+
## Template Types
6+
7+
### 1. `basic.json5` - Array/Number Problems
8+
9+
- **Use for**: Array manipulation, hash table, basic algorithms
10+
- **Examples**: Two Sum, Contains Duplicate, Product of Array Except Self
11+
- **Key features**: Simple parameters, basic return types, no special imports
12+
13+
### 2. `tree.json5` - Binary Tree Problems
14+
15+
- **Use for**: Binary tree traversal, tree manipulation, tree construction
16+
- **Examples**: Invert Binary Tree, Maximum Depth, Validate BST
17+
- **Key features**: TreeNode import, array-to-tree conversion, tree-specific logging
18+
19+
### 3. `linked_list.json5` - Linked List Problems
20+
21+
- **Use for**: Singly linked list manipulation, list reversal, merging
22+
- **Examples**: Reverse Linked List, Merge Two Lists, Remove Nth Node
23+
- **Key features**: ListNode import, array-to-list conversion, multiple parameters
24+
25+
### 4. `string.json5` - String Problems
26+
27+
- **Use for**: String manipulation, validation, parsing
28+
- **Examples**: Valid Parentheses, Longest Substring, Palindrome Check
29+
- **Key features**: String parameters, boolean returns, validation patterns
30+
31+
### 5. `matrix.json5` - 2D Array/Matrix Problems
32+
33+
- **Use for**: Matrix operations, 2D array manipulation, grid problems
34+
- **Examples**: Rotate Image, Spiral Matrix, Set Matrix Zeroes
35+
- **Key features**: 2D list types, in-place modifications, deep copy for testing
36+
37+
## Usage Instructions
38+
39+
1. **Choose the appropriate template** based on the problem's primary data structure
40+
2. **Copy the template structure** and fill in the specific problem details
41+
3. **Follow the comments** for guidance on each field
42+
4. **Use modern Python syntax** (e.g., `list[int]` instead of `List[int]`)
43+
5. **Test the generated JSON** with `make q-gen QUESTION=your_problem`
44+
45+
## Key Conventions
46+
47+
- **Naming**: Use snake_case for `question_name` and `method_name`, PascalCase for `class_name`
48+
- **Types**: Use modern Python type hints (`list[int]`, `TreeNode | None`)
49+
- **Parameters**: Match the exact parameter names from the LeetCode method signature
50+
- **Test Cases**: Use the same data format as the examples (arrays for trees/lists)
51+
- **Imports**: Only include necessary imports (`TreeNode`, `ListNode`, etc.)
52+
53+
## Common Patterns
54+
55+
### Return Types & Dummy Returns
56+
57+
- `bool``"False"`
58+
- `int``"0"`
59+
- `str``"\"\""`
60+
- `list[int]``"[]"`
61+
- `TreeNode | None``"None"`
62+
- `ListNode | None``"None"`
63+
64+
### Test Parameter Naming
65+
66+
- **Basic problems**: `param1, param2, expected`
67+
- **Tree problems**: `root_list, expected_list` (converts arrays to TreeNode)
68+
- **Linked List problems**: `head_list, param2, expected_list` (converts arrays to ListNode)
69+
70+
### Test Setup Patterns
71+
72+
- **Basic**: No setup needed (`""`)
73+
- **Tree**: `"root = TreeNode.from_list(root_list)\\nexpected = TreeNode.from_list(expected_list)"`
74+
- **Linked List**: `"head = ListNode.from_list(head_list)\\nexpected = ListNode.from_list(expected_list)"`
75+
- **Matrix (in-place)**: `"import copy\\noriginal_matrix = copy.deepcopy(matrix)"`
76+
77+
These templates ensure consistency and proper integration with the existing test framework and validation system.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
// Basic problem template for array/string/number problems
3+
// Copy this structure when creating new basic problems
4+
5+
// REQUIRED: Core identifiers (snake_case for question_name, PascalCase for class_name)
6+
"question_name": "two_sum", // Snake case from problem title
7+
"class_name": "TwoSum", // PascalCase version
8+
"method_name": "two_sum", // Snake case method name
9+
10+
// REQUIRED: Problem metadata (copy directly from LeetCode)
11+
"problem_number": "1", // String number from URL
12+
"problem_title": "Two Sum", // Exact title from LeetCode
13+
"difficulty": "Easy", // Easy|Medium|Hard
14+
"topics": "Array, Hash Table", // Comma-separated from LeetCode tags
15+
16+
// OPTIONAL: Problem categorization tags
17+
"tags": ["grind-75"], // Popular lists: grind-75, blind-75, neetcode-150, top-interview
18+
19+
// REQUIRED: Problem description (copy full description from LeetCode)
20+
"problem_description": "Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.",
21+
22+
// REQUIRED: Examples (copy from LeetCode, keep input/output as strings)
23+
"examples": [
24+
{ "input": "nums = [2,7,11,15], target = 9", "output": "[0,1]" },
25+
{ "input": "nums = [3,2,4], target = 6", "output": "[1,2]" },
26+
{ "input": "nums = [3,3], target = 6", "output": "[0,1]" }
27+
],
28+
29+
// REQUIRED: Constraints (copy exactly from LeetCode with \n for line breaks)
30+
"constraints": "- 2 <= nums.length <= 10^4\n- -10^9 <= nums[i] <= 10^9\n- -10^9 <= target <= 10^9\n- Only one valid answer exists.",
31+
32+
// REQUIRED: Method signature components
33+
"parameters": "nums: list[int], target: int", // Modern Python type hints
34+
"return_type": "list[int]", // Return type with modern syntax
35+
"dummy_return": "[]", // Default return for TODO implementation
36+
37+
// REQUIRED: Import statements (empty for basic problems, specify for TreeNode/ListNode)
38+
"imports": "",
39+
40+
// REQUIRED: Test configuration
41+
"test_cases": [
42+
{ "args": [[2, 7, 11, 15], 9], "expected": [0, 1] },
43+
{ "args": [[3, 2, 4], 6], "expected": [1, 2] },
44+
{ "args": [[3, 3], 6], "expected": [0, 1] }
45+
],
46+
47+
// REQUIRED: Test method parameters (use expected, not expected_list for basic problems)
48+
"param_names": "nums, target, expected",
49+
"param_names_with_types": "nums: list[int], target: int, expected: list[int]",
50+
51+
// REQUIRED: Test setup and logging
52+
"input_description": "nums={nums}, target={target}",
53+
"input_params": "nums, target",
54+
"expected_param": "expected",
55+
"method_args": "nums, target",
56+
"test_setup": "", // Empty for basic problems
57+
"test_logging": "", // Empty for default logging
58+
"assertion_code": "assert result == expected",
59+
60+
// REQUIRED: Notebook setup
61+
"test_input_setup": "# Example test case\nnums = [2, 7, 11, 15]\ntarget = 9",
62+
"expected_output_setup": "expected = [0, 1]"
63+
}

0 commit comments

Comments
 (0)