|
1 | 1 | # Migrate Problems to New Template Format |
2 | 2 |
|
3 | | -## Overview |
| 3 | +Migrate problems from `.templates/leetcode/json_old/` to `.templates/leetcode/json/` using the new template system. |
4 | 4 |
|
5 | | -Migrate all problems from old JSON format (`.templates/leetcode/json_old/`) to new template format (`.templates/leetcode/json/`) one by one. |
| 5 | +## Migration Steps |
6 | 6 |
|
7 | | -## Prerequisites |
| 7 | +1. **Find next**: `python .amazonq/plans/find_next_problem.py` |
| 8 | +2. **Create JSON**: Analyze old format, create new template in `.templates/leetcode/json/` |
| 9 | +3. **Generate**: `make p-gen PROBLEM=<name>` |
| 10 | +4. **Lint**: `make p-lint PROBLEM=<name>` (fix JSON if fails, regenerate with `FORCE=1`) |
| 11 | +5. **Implement**: Copy solution from `leetcode_old/` |
| 12 | +6. **Test**: `make p-test PROBLEM=<name>` |
| 13 | +7. **Enhance tests**: If only 2-3 cases, add edge cases (update JSON → regenerate → lint → test) |
| 14 | +8. **Commit**: Save changes |
8 | 15 |
|
9 | | -- New template system is ready in `.templates/leetcode/{{cookiecutter.problem_name}}/` |
10 | | -- Helper script exists: `.amazonq/plans/find_next_problem.py` |
11 | | - |
12 | | -## Process |
13 | | - |
14 | | -### Step 1: Find Next Problem |
15 | | - |
16 | | -```bash |
17 | | -python .amazonq/plans/find_next_problem.py |
18 | | -``` |
19 | | - |
20 | | -This returns the next problem to migrate (e.g., `accounts_merge`). |
21 | | - |
22 | | -### Step 2: Analyze Old JSON |
23 | | - |
24 | | -```bash |
25 | | -# Check the old format |
26 | | -cat .templates/leetcode/json_old/accounts_merge.json |
27 | | -``` |
28 | | - |
29 | | -Understand the structure and required variables. |
30 | | - |
31 | | -### Step 3: Create New JSON |
32 | | - |
33 | | -Create `.templates/leetcode/json/accounts_merge.json` with new template variables: |
34 | | - |
35 | | -**Required Variables:** |
36 | | - |
37 | | -- `problem_name` - Snake case name |
38 | | -- `solution_class_name` - Usually "Solution" |
39 | | -- `problem_number` - LeetCode number |
40 | | -- `problem_title` - Exact title |
41 | | -- `difficulty` - Easy/Medium/Hard |
42 | | -- `topics` - Comma-separated topics |
43 | | - |
44 | | -**Template-Specific Variables:** |
45 | | - |
46 | | -- `helpers_imports` - Imports for helpers.py |
47 | | -- `helpers_content` - Helper functions |
48 | | -- `helpers_run_name` - Main method name |
49 | | -- `helpers_run_signature` - Method signature |
50 | | -- `helpers_run_body` - Method implementation |
51 | | -- `helpers_assert_name` - Assert function name |
52 | | -- `helpers_assert_signature` - Assert signature |
53 | | -- `helpers_assert_body` - Assert implementation |
54 | | -- `solution_imports` - Imports for solution.py |
55 | | -- `solution_class_content` - Class-level content |
56 | | -- `solution_methods` - Array of method objects |
57 | | -- `test_imports` - Test imports |
58 | | -- `test_methods` - Array of test method objects |
59 | | -- `playground_imports` - Notebook imports |
60 | | -- `playground_setup` - Test case setup |
61 | | -- `playground_run` - Execution code |
62 | | -- `playground_assert` - Assertion code |
63 | | -- `readme_description` - Problem description |
64 | | -- `readme_constraints` - Constraints |
65 | | - |
66 | | -### Step 4: Generate and Test |
67 | | - |
68 | | -```bash |
69 | | -# Generate problem structure |
70 | | -make p-gen PROBLEM=accounts_merge |
71 | | - |
72 | | -# Lint to catch issues |
73 | | -make p-lint PROBLEM=accounts_merge |
74 | | - |
75 | | -# Fix any linting errors by updating JSON or generated files |
76 | | -``` |
77 | | - |
78 | | -### Step 5: Verify Generation |
79 | | - |
80 | | -Check generated files: |
81 | | - |
82 | | -- `leetcode/accounts_merge/README.md` |
83 | | -- `leetcode/accounts_merge/solution.py` |
84 | | -- `leetcode/accounts_merge/helpers.py` |
85 | | -- `leetcode/accounts_merge/test_solution.py` |
86 | | -- `leetcode/accounts_merge/playground.ipynb` |
87 | | - |
88 | | -### Step 6: Implement Solution |
89 | | - |
90 | | -```bash |
91 | | -# Copy implementation from old repository |
92 | | -# Find the solution in leetcode_old/ and implement in solution.py |
93 | | -# Replace TODO with actual working solution |
94 | | -``` |
95 | | - |
96 | | -### Step 7: Test Functionality |
97 | | - |
98 | | -```bash |
99 | | -# Run tests to ensure everything works |
100 | | -make p-test PROBLEM=accounts_merge |
101 | | -``` |
102 | | - |
103 | | -### Step 8: Repeat |
104 | | - |
105 | | -```bash |
106 | | -# Find next problem |
107 | | -python .amazonq/plans/find_next_problem.py |
108 | | -``` |
109 | | - |
110 | | -Repeat process until script returns "All problems updated!" |
111 | | - |
112 | | -## Migration Checklist |
113 | | - |
114 | | -For each problem: |
115 | | - |
116 | | -- [ ] Run `find_next_problem.py` to get next problem |
117 | | -- [ ] Analyze old JSON structure |
118 | | -- [ ] Create new JSON with all required variables |
119 | | -- [ ] Run `make p-gen PROBLEM=<name>` |
120 | | -- [ ] Run `make p-lint PROBLEM=<name>` and fix issues: |
121 | | - - If linting fails, fix the JSON template |
122 | | - - Re-run `make p-gen PROBLEM=<name> FORCE=1` to regenerate |
123 | | - - Re-run `make p-lint PROBLEM=<name>` to verify |
124 | | - - Iterate until linting passes to ensure reproducibility |
125 | | -- [ ] Implement solution from `leetcode_old/` repository |
126 | | -- [ ] Run `make p-test PROBLEM=<name>` to verify tests pass |
127 | | -- [ ] Commit changes |
128 | | - |
129 | | -## Common Patterns |
130 | | - |
131 | | -**Basic Problem:** |
132 | | - |
133 | | -```json |
134 | | -{ |
135 | | - "problem_name": "two_sum", |
136 | | - "solution_class_name": "Solution", |
137 | | - "helpers_run_name": "two_sum", |
138 | | - "helpers_run_signature": "(solution_class: type, nums: list[int], target: int)", |
139 | | - "helpers_run_body": "return solution_class().two_sum(nums, target)", |
140 | | - "solution_methods": [ |
141 | | - { |
142 | | - "name": "two_sum", |
143 | | - "signature": "(self, nums: list[int], target: int) -> list[int]", |
144 | | - "body": "# TODO: Implement\nreturn []" |
145 | | - } |
146 | | - ] |
147 | | -} |
148 | | -``` |
149 | | - |
150 | | -**Tree Problem:** |
151 | | - |
152 | | -```json |
153 | | -{ |
154 | | - "helpers_imports": "from leetcode_py import TreeNode", |
155 | | - "helpers_content": "def create_tree(root_list: list[int | None]) -> TreeNode[int] | None:\n return TreeNode[int].from_list(root_list)", |
156 | | - "solution_imports": "from leetcode_py import TreeNode" |
157 | | -} |
158 | | -``` |
159 | | - |
160 | | -**Design Problem:** |
161 | | - |
162 | | -```json |
163 | | -{ |
164 | | - "solution_class_name": "LRUCache", |
165 | | - "solution_methods": [ |
166 | | - { |
167 | | - "name": "__init__", |
168 | | - "signature": "(self, capacity: int)", |
169 | | - "body": "# TODO: Initialize" |
170 | | - }, |
171 | | - { |
172 | | - "name": "get", |
173 | | - "signature": "(self, key: int) -> int", |
174 | | - "body": "# TODO: Implement\nreturn -1" |
175 | | - } |
176 | | - ] |
177 | | -} |
178 | | -``` |
179 | | - |
180 | | -## Progress Tracking |
181 | | - |
182 | | -Track progress by running the script periodically: |
| 16 | +## Progress |
183 | 17 |
|
184 | 18 | ```bash |
185 | | -# Check remaining problems |
186 | | -ls .templates/leetcode/json_old/ | wc -l # Total old problems |
187 | | -ls .templates/leetcode/json/ | wc -l # Migrated problems |
188 | | -python .amazonq/plans/find_next_problem.py # Next to migrate |
| 19 | +python .amazonq/plans/find_next_problem.py # Next problem or "All problems updated!" |
189 | 20 | ``` |
190 | | - |
191 | | -## Completion |
192 | | - |
193 | | -When `find_next_problem.py` returns "All problems updated!", the migration is complete. |
0 commit comments