Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: update trie json
  • Loading branch information
wislertt committed Sep 5, 2025
commit 4e18df4c27ea630662ef0fc3da12a8e915dc83a2
7 changes: 7 additions & 0 deletions .amazonq/rules/problem-creation.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ When creating JSON properties that use PascalCase (solution_class_name, test_cla
- Complex test setup with operation sequences
- Import custom class in test_imports

### Dict-based Tree Problems (Trie, etc.)

- Add `"solution_imports": "from leetcode_py.data_structures import DictTree"`
- Inherit from `DictTree[str]` for string-based trees like Trie
- Provides automatic visualization capabilities
- Use `dict[str, Any]` for internal tree structure

## Generation Commands

```bash
Expand Down
4 changes: 2 additions & 2 deletions .templates/leetcode/json/implement_trie_prefix_tree.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"problem_name": "implement_trie_prefix_tree",
"solution_class_name": "Trie",
"solution_class_name": "Trie(DictTree[str])",
"problem_number": "208",
"problem_title": "Implement Trie (Prefix Tree)",
"difficulty": "Medium",
Expand All @@ -14,7 +14,7 @@
],
"readme_constraints": "- `1 <= word.length, prefix.length <= 2000`\n- `word` and `prefix` consist only of lowercase English letters.\n- At most `3 * 10^4` calls **in total** will be made to `insert`, `search`, and `starts_with`.",
"readme_additional": "",
"solution_imports": "",
"solution_imports": "from leetcode_py.data_structures import DictTree",
"solution_methods": [
{ "name": "__init__", "parameters": "", "return_type": "None", "dummy_return": "" },
{ "name": "insert", "parameters": "word: str", "return_type": "None", "dummy_return": "" },
Expand Down
12 changes: 6 additions & 6 deletions leetcode/implement_trie_prefix_tree/playground.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
},
{
"cell_type": "code",
"execution_count": 4,
"id": "8d00661e",
"execution_count": 5,
"id": "f3bac41e",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -170,10 +170,10 @@
"</svg>\n"
],
"text/plain": [
"<solution.Trie at 0x1043da270>"
"<solution.Trie at 0x10406a270>"
]
},
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -184,7 +184,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"id": "test",
"metadata": {},
"outputs": [],
Expand All @@ -207,7 +207,7 @@
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"nbconvert_exporter": "python3",
"pygments_lexer": "ipython3",
"version": "3.13.7"
}
Expand Down
71 changes: 0 additions & 71 deletions leetcode/implement_trie_prefix_tree/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,77 +30,6 @@ class TestImplementTriePrefixTree:
[None, None, False, True, None, True, True],
),
(["Trie", "search", "starts_with"], [[], ["empty"], ["empty"]], [None, False, False]),
(
["Trie", "insert", "insert", "search", "search", "starts_with"],
[[], ["cat"], ["car"], ["cat"], ["card"], ["ca"]],
[None, None, None, True, False, True],
),
(
["Trie", "insert", "search", "insert", "search", "starts_with"],
[[], ["abc"], ["ab"], ["ab"], ["ab"], ["a"]],
[None, None, False, None, True, True],
),
(
["Trie", "insert", "insert", "insert", "search", "starts_with"],
[[], [""], ["a"], ["ab"], [""], [""]],
[None, None, None, None, True, True],
),
(
["Trie", "insert", "search", "starts_with", "insert", "search"],
[[], ["z"], ["z"], ["z"], ["zzz"], ["zzz"]],
[None, None, True, True, None, True],
),
(
["Trie", "insert", "insert", "search", "search", "starts_with", "starts_with"],
[[], ["prefix"], ["prefixsuffix"], ["prefix"], ["prefixsuffix"], ["pre"], ["prefixs"]],
[None, None, None, True, True, True, True],
),
(
["Trie", "insert", "insert", "search", "starts_with"],
[[], ["word"], ["word"], ["word"], ["wor"]],
[None, None, None, True, True],
),
(
["Trie", "insert", "search", "search", "starts_with", "starts_with"],
[[], ["Word"], ["word"], ["Word"], ["W"], ["w"]],
[None, None, False, True, True, False],
),
(
["Trie", "insert", "insert", "search", "search", "search", "starts_with", "starts_with"],
[[], ["a"], ["b"], ["a"], ["b"], ["c"], ["a"], ["b"]],
[None, None, None, True, True, False, True, True],
),
(
[
"Trie",
"insert",
"insert",
"insert",
"insert",
"search",
"search",
"search",
"search",
"search",
"starts_with",
"starts_with",
],
[
[],
["car"],
["card"],
["care"],
["careful"],
["car"],
["card"],
["care"],
["careful"],
["ca"],
["car"],
["care"],
],
[None, None, None, None, None, True, True, True, True, False, True, True],
),
],
)
@logged_test
Expand Down