Skip to content

Commit 4587633

Browse files
committed
fix: fix template
1 parent 5bc04a7 commit 4587633

File tree

3 files changed

+75
-75
lines changed

3 files changed

+75
-75
lines changed
Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,82 @@
11
{
2-
// Design problem template - for data structure design problems
3-
// Example: LRU Cache
4-
// Key differences: Custom class name, multiple methods, complex test setup
2+
// Design problem template - for data structure design problems
3+
// Example: LRU Cache
4+
// Key differences: Custom class name, multiple methods, complex test setup
55

6-
// === PROBLEM IDENTIFICATION ===
7-
"problem_name": "lru_cache", // snake_case: used for directory/file names
8-
"solution_class_name": "LRUCache", // IMPORTANT: Custom class name for design problems
9-
"problem_number": "146", // LeetCode problem number as string
10-
"problem_title": "LRU Cache", // Exact title from LeetCode
11-
"difficulty": "Medium", // Easy, Medium, Hard
12-
"topics": "Hash Table, Linked List, Design, Doubly-Linked List", // Design-related topics
13-
"tags": ["grind-75"], // Optional: common problem set tags
6+
// === PROBLEM IDENTIFICATION ===
7+
problem_name: "lru_cache", // snake_case: used for directory/file names
8+
solution_class_name: "LRUCache", // IMPORTANT: Custom class name for design problems
9+
problem_number: "146", // LeetCode problem number as string
10+
problem_title: "LRU Cache", // Exact title from LeetCode
11+
difficulty: "Medium", // Easy, Medium, Hard
12+
topics: "Hash Table, Linked List, Design, Doubly-Linked List", // Design-related topics
13+
tags: ["grind-75"], // Optional: common problem set tags
1414

15-
// === README CONTENT ===
16-
// IMPORTANT: Preserve rich HTML content from LeetCode including:
17-
// - Code snippets with backticks: `code`
18-
// - Bold text: **bold** or <strong>bold</strong>
19-
// - Italic text: *italic* or <em>italic</em>
20-
// - Images: <img> tags with proper src and styling
21-
// - HTML formatting: <p>, <br>, <ul>, <li>, etc.
22-
// - Mathematical expressions and special characters
23-
"readme_description": "Design a data structure that follows the constraints of a Least Recently Used (LRU) cache.\\n\\nImplement the `LRUCache` class:\\n\\n- `LRUCache(int capacity)` Initialize the LRU cache with positive size capacity\\n- `int get(int key)` Return the value of the key if the key exists, otherwise return -1\\n- `void put(int key, int value)` Update the value of the key if the key exists. Otherwise, add the key-value pair to the cache. If the number of keys exceeds the capacity from this operation, evict the least recently used key\\n\\nThe functions `get` and `put` must each run in `O(1)` average time complexity.",
15+
// === README CONTENT ===
16+
// IMPORTANT: Preserve rich HTML content from LeetCode including:
17+
// - Code snippets with backticks: `code`
18+
// - Bold text: **bold** or <strong>bold</strong>
19+
// - Italic text: *italic* or <em>italic</em>
20+
// - Images: <img> tags with proper src and styling
21+
// - HTML formatting: <p>, <br>, <ul>, <li>, etc.
22+
// - Mathematical expressions and special characters
23+
readme_description: "Design a data structure that follows the constraints of a Least Recently Used (LRU) cache.\\n\\nImplement the `LRUCache` class:\\n\\n- `LRUCache(int capacity)` Initialize the LRU cache with positive size capacity\\n- `int get(int key)` Return the value of the key if the key exists, otherwise return -1\\n- `void put(int key, int value)` Update the value of the key if the key exists. Otherwise, add the key-value pair to the cache. If the number of keys exceeds the capacity from this operation, evict the least recently used key\\n\\nThe functions `get` and `put` must each run in `O(1)` average time complexity.",
2424

25-
"readme_examples": [
26-
{
27-
// Design problems often have complex operation sequences
28-
"content": "```\\nInput\\n[\\\"LRUCache\\\", \\\"put\\\", \\\"put\\\", \\\"get\\\", \\\"put\\\", \\\"get\\\", \\\"put\\\", \\\"get\\\", \\\"get\\\", \\\"get\\\"]\\n[[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]\\nOutput\\n[null, null, null, 1, null, -1, null, -1, 3, 4]\\n\\nExplanation\\nLRUCache lRUCache = new LRUCache(2);\\nlRUCache.put(1, 1); // cache is {1=1}\\nlRUCache.put(2, 2); // cache is {1=1, 2=2}\\nlRUCache.get(1); // return 1\\nlRUCache.put(3, 3); // LRU key was 2, evicts key 2, cache is {1=1, 3=3}\\nlRUCache.get(2); // returns -1 (not found)\\nlRUCache.put(4, 4); // LRU key was 1, evicts key 1, cache is {4=4, 3=3}\\nlRUCache.get(1); // return -1 (not found)\\nlRUCache.get(3); // return 3\\nlRUCache.get(4); // return 4\\n```"
29-
}
30-
],
25+
readme_examples: [
26+
{
27+
// Design problems often have complex operation sequences
28+
content: '```\\nInput\\n[\\"LRUCache\\", \\"put\\", \\"put\\", \\"get\\", \\"put\\", \\"get\\", \\"put\\", \\"get\\", \\"get\\", \\"get\\"]\\n[[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]\\nOutput\\n[null, null, null, 1, null, -1, null, -1, 3, 4]\\n\\nExplanation\\nLRUCache lRUCache = new LRUCache(2);\\nlRUCache.put(1, 1); // cache is {1=1}\\nlRUCache.put(2, 2); // cache is {1=1, 2=2}\\nlRUCache.get(1); // return 1\\nlRUCache.put(3, 3); // LRU key was 2, evicts key 2, cache is {1=1, 3=3}\\nlRUCache.get(2); // returns -1 (not found)\\nlRUCache.put(4, 4); // LRU key was 1, evicts key 1, cache is {4=4, 3=3}\\nlRUCache.get(1); // return -1 (not found)\\nlRUCache.get(3); // return 3\\nlRUCache.get(4); // return 4\\n```',
29+
},
30+
],
3131

32-
"readme_constraints": "- 1 <= capacity <= 3000\\n- 0 <= key <= 10^4\\n- 0 <= value <= 10^5\\n- At most 2 * 10^5 calls will be made to get and put",
33-
"readme_additional": "",
32+
readme_constraints: "- 1 <= capacity <= 3000\\n- 0 <= key <= 10^4\\n- 0 <= value <= 10^5\\n- At most 2 * 10^5 calls will be made to get and put",
33+
readme_additional: "",
3434

35-
// === SOLUTION TEMPLATE ===
36-
"solution_imports": "", // Usually empty for design problems
37-
// IMPORTANT: Design problems have multiple methods including __init__
38-
"solution_methods": [
39-
{
40-
"name": "__init__", // Constructor method
41-
"parameters": "capacity: int", // Constructor parameters
42-
"return_type": "None", // Constructor returns None
43-
"dummy_return": "" // Empty for None return
44-
},
45-
{
46-
"name": "get", // Instance method
47-
"parameters": "key: int",
48-
"return_type": "int",
49-
"dummy_return": "-1" // Specific default for this method
50-
},
51-
{
52-
"name": "put", // Instance method
53-
"parameters": "key: int, value: int",
54-
"return_type": "None",
55-
"dummy_return": "" // Empty for None return
56-
}
57-
],
35+
// === SOLUTION TEMPLATE ===
36+
solution_imports: "", // Usually empty for design problems
37+
// IMPORTANT: Design problems have multiple methods including __init__
38+
solution_methods: [
39+
{
40+
name: "__init__", // Constructor method
41+
parameters: "capacity: int", // Constructor parameters
42+
return_type: "None", // Constructor returns None
43+
dummy_return: "", // Empty for None return
44+
},
45+
{
46+
name: "get", // Instance method
47+
parameters: "key: int",
48+
return_type: "int",
49+
dummy_return: "-1", // Specific default for this method
50+
},
51+
{
52+
name: "put", // Instance method
53+
parameters: "key: int, value: int",
54+
return_type: "None",
55+
dummy_return: "", // Empty for None return
56+
},
57+
],
5858

59-
// === TEST CONFIGURATION ===
60-
// IMPORTANT: Design problems import the custom class, not Solution
61-
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import LRUCache",
62-
"test_class_name": "LruCache", // PascalCase: TestClassName for pytest class
63-
"test_helper_methods": [], // Often empty for design problems
64-
"test_methods": [
65-
{
66-
"name": "test_lru_cache",
67-
// IMPORTANT: Design tests use operations, inputs, expected pattern
68-
"parametrize": "operations, inputs, expected",
69-
"parametrize_typed": "operations: list[str], inputs: list[list[int]], expected: list[int | None]",
70-
"test_cases": "[([\"LRUCache\", \"put\", \"put\", \"get\", \"put\", \"get\", \"put\", \"get\", \"get\", \"get\"], [[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]], [None, None, None, 1, None, -1, None, -1, 3, 4])]",
71-
// IMPORTANT: Complex test body that executes operation sequences
72-
"body": "cache: LRUCache | None = None\nresults: list[int | None] = []\nfor i, op in enumerate(operations):\n if op == \"LRUCache\":\n cache = LRUCache(inputs[i][0])\n results.append(None)\n elif op == \"get\" and cache is not None:\n results.append(cache.get(inputs[i][0]))\n elif op == \"put\" and cache is not None:\n cache.put(inputs[i][0], inputs[i][1])\n results.append(None)\nassert results == expected"
73-
}
74-
],
59+
// === TEST CONFIGURATION ===
60+
// IMPORTANT: Design problems import the custom class, not Solution
61+
test_imports: "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import LRUCache",
62+
test_class_name: "LRUCache", // PascalCase: TestClassName for pytest class
63+
test_helper_methods: [], // Often empty for design problems
64+
test_methods: [
65+
{
66+
name: "test_lru_cache",
67+
// IMPORTANT: Design tests use operations, inputs, expected pattern
68+
parametrize: "operations, inputs, expected",
69+
parametrize_typed: "operations: list[str], inputs: list[list[int]], expected: list[int | None]",
70+
test_cases: '[(["LRUCache", "put", "put", "get", "put", "get", "put", "get", "get", "get"], [[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]], [None, None, None, 1, None, -1, None, -1, 3, 4])]',
71+
// IMPORTANT: Complex test body that executes operation sequences
72+
body: 'cache: LRUCache | None = None\nresults: list[int | None] = []\nfor i, op in enumerate(operations):\n if op == "LRUCache":\n cache = LRUCache(inputs[i][0])\n results.append(None)\n elif op == "get" and cache is not None:\n results.append(cache.get(inputs[i][0]))\n elif op == "put" and cache is not None:\n cache.put(inputs[i][0], inputs[i][1])\n results.append(None)\nassert results == expected',
73+
},
74+
],
7575

76-
// === PLAYGROUND NOTEBOOK ===
77-
// IMPORTANT: Design playground uses operation sequences like tests
78-
"playground_imports": "from solution import LRUCache",
79-
"playground_test_case": "# Example test case\noperations = ['LRUCache', 'put', 'put', 'get', 'put', 'get', 'put', 'get', 'get', 'get']\ninputs = [[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]\nexpected = [None, None, None, 1, None, -1, None, -1, 3, 4]",
80-
"playground_execution": "cache = None\nresults: list[int | None] = []\nfor i, op in enumerate(operations):\n if op == 'LRUCache':\n cache = LRUCache(inputs[i][0])\n results.append(None)\n elif op == 'get' and cache is not None:\n results.append(cache.get(inputs[i][0]))\n elif op == 'put' and cache is not None:\n cache.put(inputs[i][0], inputs[i][1])\n results.append(None)\nresults",
81-
"playground_assertion": "assert results == expected"
76+
// === PLAYGROUND NOTEBOOK ===
77+
// IMPORTANT: Design playground uses operation sequences like tests
78+
playground_imports: "from solution import LRUCache",
79+
playground_test_case: "# Example test case\noperations = ['LRUCache', 'put', 'put', 'get', 'put', 'get', 'put', 'get', 'get', 'get']\ninputs = [[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]\nexpected = [None, None, None, 1, None, -1, None, -1, 3, 4]",
80+
playground_execution: "cache = None\nresults: list[int | None] = []\nfor i, op in enumerate(operations):\n if op == 'LRUCache':\n cache = LRUCache(inputs[i][0])\n results.append(None)\n elif op == 'get' and cache is not None:\n results.append(cache.get(inputs[i][0]))\n elif op == 'put' and cache is not None:\n cache.put(inputs[i][0], inputs[i][1])\n results.append(None)\nresults",
81+
playground_assertion: "assert results == expected",
8282
}

.templates/leetcode/json/lru_cache.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
}
2727
],
2828
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import LRUCache",
29-
"test_class_name": "LruCache",
29+
"test_class_name": "LRUCache",
3030
"test_helper_methods": [],
3131
"test_methods": [
3232
{

leetcode/lru_cache/tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from .solution import LRUCache
66

77

8-
class TestLruCache:
8+
class TestLRUCache:
99
@pytest.mark.parametrize(
1010
"operations, inputs, expected",
1111
[

0 commit comments

Comments
 (0)