|
1 |
| -# LeetCode Problem Template Examples |
| 1 | +# JSON Template Examples |
2 | 2 |
|
3 |
| -This directory contains comprehensive JSON5 template examples for different types of LeetCode problems. These examples serve as references when creating new problems using the universal cookiecutter template. |
| 3 | +This directory contains comprehensive examples for creating LeetCode problem templates. |
4 | 4 |
|
5 |
| -## Template Types |
| 5 | +## Files |
6 | 6 |
|
7 |
| -### 1. `basic.json5` - Basic Algorithm Problems |
| 7 | +- **`basic.json5`** - Covers all standard problem types: |
| 8 | + - Array problems (Container With Most Water) |
| 9 | + - String problems (with JSON escaping notes) |
| 10 | + - Tree problems (import and parameter examples) |
| 11 | + - Linked list problems (import and parameter examples) |
| 12 | + - Matrix problems |
| 13 | + - Number problems |
8 | 14 |
|
9 |
| -**Use for:** Array, string, number, hash table problems |
10 |
| -**Examples:** Container With Most Water, Two Sum, Valid Palindrome |
11 |
| -**Key features:** |
| 15 | +- **`design.json5`** - Data structure design problems: |
| 16 | + - Custom class names (LRUCache, not Solution) |
| 17 | + - Multiple methods including `__init__` |
| 18 | + - Complex test setup with operation sequences |
| 19 | + - Custom imports |
12 | 20 |
|
13 |
| -- Simple `Solution` class with single method |
14 |
| -- Standard test parametrization |
15 |
| -- Basic playground setup |
| 21 | +## Key Differences |
16 | 22 |
|
17 |
| -### 2. `tree.json5` - Binary Tree Problems |
| 23 | +### Standard Problems (basic.json5) |
18 | 24 |
|
19 |
| -**Use for:** Binary tree, BST, tree traversal problems |
20 |
| -**Examples:** Invert Binary Tree, Maximum Depth, Serialize Tree |
21 |
| -**Key features:** |
| 25 | +- `solution_class_name`: Always "Solution" |
| 26 | +- Single method (usually) |
| 27 | +- Simple test cases with direct assertions |
| 28 | +- Standard imports |
22 | 29 |
|
23 |
| -- `TreeNode` imports and conversions |
24 |
| -- `TreeNode.from_list()` and `TreeNode.to_list()` in tests |
25 |
| -- Tree visualization support |
| 30 | +### Design Problems (design.json5) |
26 | 31 |
|
27 |
| -### 3. `linked_list.json5` - Linked List Problems |
| 32 | +- `solution_class_name`: Custom class name (e.g., "LRUCache") |
| 33 | +- Multiple methods including constructor |
| 34 | +- Operation sequence testing |
| 35 | +- Import custom class in tests |
28 | 36 |
|
29 |
| -**Use for:** Singly/doubly linked list problems |
30 |
| -**Examples:** Reverse Linked List, Merge Lists, Detect Cycle |
31 |
| -**Key features:** |
| 37 | +## Critical Notes |
32 | 38 |
|
33 |
| -- `ListNode` imports and conversions |
34 |
| -- `ListNode.from_list()` and `ListNode.to_list()` in tests |
35 |
| -- Arrow visualization support |
36 |
| - |
37 |
| -### 4. `design.json5` - Data Structure Design Problems |
38 |
| - |
39 |
| -**Use for:** Design problems requiring custom classes |
40 |
| -**Examples:** LRU Cache, Implement Trie, Design HashMap |
41 |
| -**Key features:** |
42 |
| - |
43 |
| -- Custom class names (not `Solution`) |
44 |
| -- Multiple methods including `__init__` |
45 |
| -- Complex operation sequence testing |
46 |
| -- Type annotations for complex test logic |
47 |
| - |
48 |
| -### 5. `matrix.json5` - 2D Array/Matrix Problems |
49 |
| - |
50 |
| -**Use for:** Matrix manipulation, 2D array problems |
51 |
| -**Examples:** Spiral Matrix, Rotate Image, Search 2D Matrix |
52 |
| -**Key features:** |
53 |
| - |
54 |
| -- 2D array type annotations (`list[list[int]]`) |
55 |
| -- Visual examples with images |
56 |
| -- Matrix-specific test cases |
57 |
| - |
58 |
| -## Usage Guidelines |
59 |
| - |
60 |
| -### Problem Type Detection |
61 |
| - |
62 |
| -1. **Basic**: Single algorithm, simple input/output |
63 |
| -2. **Tree**: Mentions "tree", "node", uses tree terminology |
64 |
| -3. **Linked List**: Mentions "linked list", "node", list operations |
65 |
| -4. **Design**: "Design", "Implement", multiple operations |
66 |
| -5. **Matrix**: "matrix", "2D array", "grid", visual layout |
67 |
| - |
68 |
| -### Key Template Fields |
69 |
| - |
70 |
| -#### Required Fields |
71 |
| - |
72 |
| -- `problem_name`: snake_case identifier |
73 |
| -- `solution_class_name`: "Solution" or custom class name |
74 |
| -- `problem_number`: LeetCode number as string |
75 |
| -- `problem_title`: Exact LeetCode title |
76 |
| -- `difficulty`: "Easy", "Medium", or "Hard" |
77 |
| -- `topics`: Comma-separated topic string |
78 |
| -- `solution_methods`: Array of method definitions |
79 |
| - |
80 |
| -#### Important Patterns |
81 |
| - |
82 |
| -- **Type Hints**: Use modern syntax (`list[int]`, `dict[str, int]`, `Type | None`) |
83 |
| -- **Method Names**: Always snake_case |
84 |
| -- **Test Cases**: String representation of Python data structures |
85 |
| -- **Imports**: Include necessary helper classes (TreeNode, ListNode) |
86 |
| - |
87 |
| -#### PascalCase Naming Rules |
88 |
| - |
89 |
| -For `solution_class_name` and `test_class_name` properties: |
90 |
| - |
91 |
| -- **Acronyms**: Keep all caps ("LRUCache" not "LruCache") |
92 |
| -- **Roman numerals**: Keep all caps ("ReverseLinkedListII" not "ReverseLinkedListIi") |
93 |
| -- **Common patterns**: "BST", "DFS", "BFS", "API", "URL", "HTML", "JSON", "XML" |
94 |
| - |
95 |
| -### Template Selection Process |
96 |
| - |
97 |
| -1. Identify problem type from description/title |
98 |
| -2. Choose appropriate template from examples |
99 |
| -3. Customize fields for specific problem |
100 |
| -4. Ensure imports match problem requirements |
101 |
| -5. Verify test setup matches data structures used |
102 |
| - |
103 |
| -## Validation |
104 |
| - |
105 |
| -All templates are validated against: |
106 |
| - |
107 |
| -- Cookiecutter template compatibility |
108 |
| -- Linting requirements (black, isort, ruff, mypy) |
109 |
| -- Test framework integration |
110 |
| -- Notebook JSON format compliance |
111 |
| - |
112 |
| -## Notes |
113 |
| - |
114 |
| -- JSON5 format allows comments for documentation |
115 |
| -- All examples are based on working, tested templates |
116 |
| -- Templates are designed for the universal cookiecutter system |
117 |
| -- Examples include both simple and complex problem patterns |
| 39 | +- **JSON Escaping**: Use single quotes for Python strings in playground fields |
| 40 | +- **Type Hints**: Use modern syntax (`list[int]`, `TreeNode | None`) |
| 41 | +- **PascalCase**: Keep acronyms ALL CAPS (LRUCache, ReverseLinkedListII) |
0 commit comments