Skip to content

Commit 094e2bf

Browse files
committed
feat: add find_median_from_data_stream
1 parent 816db0a commit 094e2bf

File tree

81 files changed

+3027
-14
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+3027
-14
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"problem_name": "climbing_stairs",
3+
"solution_class_name": "Solution",
4+
"problem_number": "70",
5+
"problem_title": "Climbing Stairs",
6+
"difficulty": "Easy",
7+
"topics": "Math, Dynamic Programming, Memoization",
8+
"_tags": { "list": ["grind-75"] },
9+
"readme_description": "You are climbing a staircase. It takes `n` steps to reach the top.\n\nEach time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top?",
10+
"_readme_examples": {
11+
"list": [
12+
{
13+
"content": "```\nInput: n = 2\nOutput: 2\n```\n**Explanation:** There are two ways to climb to the top.\n1. 1 step + 1 step\n2. 2 steps"
14+
},
15+
{
16+
"content": "```\nInput: n = 3\nOutput: 3\n```\n**Explanation:** There are three ways to climb to the top.\n1. 1 step + 1 step + 1 step\n2. 1 step + 2 steps\n3. 2 steps + 1 step"
17+
}
18+
]
19+
},
20+
"readme_constraints": "- 1 <= n <= 45",
21+
"readme_additional": "",
22+
"helpers_imports": "",
23+
"helpers_content": "",
24+
"helpers_run_name": "climb_stairs",
25+
"helpers_run_signature": "(solution_class: type, n: int)",
26+
"helpers_run_body": " implementation = solution_class()\n return implementation.climb_stairs(n)",
27+
"helpers_assert_name": "climb_stairs",
28+
"helpers_assert_signature": "(result: int, expected: int) -> bool",
29+
"helpers_assert_body": " assert result == expected\n return True",
30+
"solution_imports": "",
31+
"solution_contents": "",
32+
"solution_class_content": "",
33+
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .helpers import assert_climb_stairs, run_climb_stairs\nfrom .solution import Solution",
34+
"test_content": "",
35+
"test_class_name": "ClimbingStairs",
36+
"test_class_content": " def setup_method(self):\n self.solution = Solution()",
37+
"_solution_methods": {
38+
"list": [
39+
{
40+
"name": "climb_stairs",
41+
"signature": "(self, n: int) -> int",
42+
"body": " # TODO: Implement climb_stairs\n return 1"
43+
}
44+
]
45+
},
46+
"_test_helper_methods": {
47+
"list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }]
48+
},
49+
"_test_methods": {
50+
"list": [
51+
{
52+
"name": "test_climb_stairs",
53+
"signature": "(self, n: int, expected: int)",
54+
"parametrize": "n, expected",
55+
"test_cases": "[(1, 1), (2, 2), (3, 3), (4, 5), (5, 8), (6, 13), (10, 89), (20, 10946), (45, 1836311903)]",
56+
"body": " result = run_climb_stairs(Solution, n)\n assert_climb_stairs(result, expected)"
57+
}
58+
]
59+
},
60+
"playground_imports": "from helpers import run_climb_stairs, assert_climb_stairs\nfrom solution import Solution",
61+
"playground_setup": "# Example test case\nn = 3\nexpected = 3",
62+
"playground_run": "result = run_climb_stairs(Solution, n)\nresult",
63+
"playground_assert": "assert_climb_stairs(result, expected)"
64+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"problem_name": "clone_graph",
3+
"solution_class_name": "Solution",
4+
"problem_number": "133",
5+
"problem_title": "Clone Graph",
6+
"difficulty": "Medium",
7+
"topics": "Hash Table, Depth-First Search, Breadth-First Search, Graph",
8+
"_tags": { "list": ["grind-75"] },
9+
"readme_description": "Given a reference of a node in a **connected** undirected graph.\n\nReturn a **deep copy** (clone) of the graph.\n\nEach node in the graph contains a value (`int`) and a list (`List[Node]`) of its neighbors.\n\n```\nclass Node {\n public int val;\n public List<Node> neighbors;\n}\n```\n\n**Test case format:**\n\nFor simplicity, each node's value is the same as the node's index (1-indexed). For example, the first node with `val == 1`, the second node with `val == 2`, and so on. The graph is represented in the test case using an adjacency list.\n\n**An adjacency list** is a collection of unordered **lists** used to represent a finite graph. Each list describes the set of neighbors of a node in the graph.\n\nThe given node will always be the first node with `val = 1`. You must return the **copy of the given node** as a reference to the cloned graph.",
10+
"_readme_examples": {
11+
"list": [
12+
{
13+
"content": "![Example 1](https://assets.leetcode.com/uploads/2019/11/04/133_clone_graph_question.png)\n\n```\nInput: adjList = [[2,4],[1,3],[2,4],[1,3]]\nOutput: [[2,4],[1,3],[2,4],[1,3]]\n```\n**Explanation:** There are 4 nodes in the graph.\n1st node (val = 1)'s neighbors are 2nd node (val = 2) and 4th node (val = 4).\n2nd node (val = 2)'s neighbors are 1st node (val = 1) and 3rd node (val = 3).\n3rd node (val = 3)'s neighbors are 2nd node (val = 2) and 4th node (val = 4).\n4th node (val = 4)'s neighbors are 1st node (val = 1) and 3rd node (val = 3)."
14+
},
15+
{
16+
"content": "![Example 2](https://assets.leetcode.com/uploads/2020/01/07/graph.png)\n\n```\nInput: adjList = [[]]\nOutput: [[]]\n```\n**Explanation:** Note that the input contains one empty list. The graph consists of only one node with val = 1 and it does not have any neighbors."
17+
},
18+
{
19+
"content": "```\nInput: adjList = []\nOutput: []\n```\n**Explanation:** This an empty graph, it does not have any nodes."
20+
}
21+
]
22+
},
23+
"readme_constraints": "- The number of nodes in the graph is in the range `[0, 100]`.\n- `1 <= Node.val <= 100`\n- `Node.val` is unique for each node.\n- There are no repeated edges and no self-loops in the graph.\n- The Graph is connected and all nodes can be visited starting from the given node.",
24+
"readme_additional": "",
25+
"helpers_imports": "from leetcode_py import GraphNode",
26+
"helpers_content": "",
27+
"helpers_run_name": "clone_graph",
28+
"helpers_run_signature": "(solution_class: type, adj_list: list[list[int]])",
29+
"helpers_run_body": " node = GraphNode.from_adjacency_list(adj_list)\n implementation = solution_class()\n return implementation.clone_graph(node)",
30+
"helpers_assert_name": "clone_graph",
31+
"helpers_assert_signature": "(result: GraphNode | None, adj_list: list[list[int]]) -> bool",
32+
"helpers_assert_body": " original = GraphNode.from_adjacency_list(adj_list)\n if result is None:\n assert original is None\n else:\n assert result.is_clone(original)\n return True",
33+
"solution_imports": "from leetcode_py import GraphNode",
34+
"solution_contents": "",
35+
"solution_class_content": "",
36+
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .helpers import assert_clone_graph, run_clone_graph\nfrom .solution import Solution",
37+
"test_content": "",
38+
"test_class_name": "CloneGraph",
39+
"test_class_content": " def setup_method(self):\n self.solution = Solution()",
40+
"_solution_methods": {
41+
"list": [
42+
{
43+
"name": "clone_graph",
44+
"signature": "(self, node: GraphNode | None) -> GraphNode | None",
45+
"body": " # TODO: Implement clone_graph\n return None"
46+
}
47+
]
48+
},
49+
"_test_helper_methods": {
50+
"list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }]
51+
},
52+
"_test_methods": {
53+
"list": [
54+
{
55+
"name": "test_clone_graph",
56+
"signature": "(self, adj_list: list[list[int]])",
57+
"parametrize": "adj_list",
58+
"test_cases": "[[[2, 4], [1, 3], [2, 4], [1, 3]], [[]], []]",
59+
"body": " result = run_clone_graph(Solution, adj_list)\n assert_clone_graph(result, adj_list)"
60+
}
61+
]
62+
},
63+
"playground_imports": "from helpers import run_clone_graph, assert_clone_graph\nfrom solution import Solution\nfrom leetcode_py import GraphNode",
64+
"playground_setup": "# Example test case\nadj_list = [[2,4],[1,3],[2,4],[1,3]]",
65+
"playground_run": "result = run_clone_graph(Solution, adj_list)\nresult",
66+
"playground_assert": "assert_clone_graph(result, adj_list)"
67+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"problem_name": "coin_change",
3+
"solution_class_name": "Solution",
4+
"problem_number": "322",
5+
"problem_title": "Coin Change",
6+
"difficulty": "Medium",
7+
"topics": "Array, Dynamic Programming, Breadth-First Search",
8+
"_tags": { "list": ["grind-75"] },
9+
"readme_description": "You are given an integer array `coins` representing coins of different denominations and an integer `amount` representing a total amount of money.\n\nReturn the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return `-1`.\n\nYou may assume that you have an infinite number of each kind of coin.",
10+
"_readme_examples": {
11+
"list": [
12+
{
13+
"content": "```\nInput: coins = [1,2,5], amount = 11\nOutput: 3\n```\n**Explanation:** 11 = 5 + 5 + 1"
14+
},
15+
{ "content": "```\nInput: coins = [2], amount = 3\nOutput: -1\n```" },
16+
{ "content": "```\nInput: coins = [1], amount = 0\nOutput: 0\n```" }
17+
]
18+
},
19+
"readme_constraints": "- `1 <= coins.length <= 12`\n- `1 <= coins[i] <= 2^31 - 1`\n- `0 <= amount <= 10^4`",
20+
"readme_additional": "",
21+
"helpers_imports": "",
22+
"helpers_content": "",
23+
"helpers_run_name": "coin_change",
24+
"helpers_run_signature": "(solution_class: type, coins: list[int], amount: int)",
25+
"helpers_run_body": " implementation = solution_class()\n return implementation.coin_change(coins, amount)",
26+
"helpers_assert_name": "coin_change",
27+
"helpers_assert_signature": "(result: int, expected: int) -> bool",
28+
"helpers_assert_body": " assert result == expected\n return True",
29+
"solution_imports": "",
30+
"solution_contents": "",
31+
"solution_class_content": "",
32+
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .helpers import assert_coin_change, run_coin_change\nfrom .solution import Solution",
33+
"test_content": "",
34+
"test_class_name": "CoinChange",
35+
"test_class_content": " def setup_method(self):\n self.solution = Solution()",
36+
"_solution_methods": {
37+
"list": [
38+
{
39+
"name": "coin_change",
40+
"signature": "(self, coins: list[int], amount: int) -> int",
41+
"body": " # TODO: Implement coin_change\n return -1"
42+
}
43+
]
44+
},
45+
"_test_helper_methods": {
46+
"list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }]
47+
},
48+
"_test_methods": {
49+
"list": [
50+
{
51+
"name": "test_coin_change",
52+
"signature": "(self, coins: list[int], amount: int, expected: int)",
53+
"parametrize": "coins, amount, expected",
54+
"test_cases": "[([1, 2, 5], 11, 3), ([2], 3, -1), ([1], 0, 0), ([1, 3, 4], 6, 2), ([2, 5, 10, 1], 27, 4), ([5], 3, -1), ([1], 1, 1), ([1, 2], 2, 1), ([186, 419, 83, 408], 6249, 20)]",
55+
"body": " result = run_coin_change(Solution, coins, amount)\n assert_coin_change(result, expected)"
56+
}
57+
]
58+
},
59+
"playground_imports": "from helpers import run_coin_change, assert_coin_change\nfrom solution import Solution",
60+
"playground_setup": "# Example test case\ncoins = [1, 2, 5]\namount = 11\nexpected = 3",
61+
"playground_run": "result = run_coin_change(Solution, coins, amount)\nresult",
62+
"playground_assert": "assert_coin_change(result, expected)"
63+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"problem_name": "combination_sum",
3+
"solution_class_name": "Solution",
4+
"problem_number": "39",
5+
"problem_title": "Combination Sum",
6+
"difficulty": "Medium",
7+
"topics": "Array, Backtracking",
8+
"_tags": { "list": ["grind-75"] },
9+
"readme_description": "Given an array of **distinct** integers `candidates` and a target integer `target`, return *a list of all **unique combinations** of* `candidates` *where the chosen numbers sum to* `target`. You may return the combinations in **any order**.\n\nThe **same** number may be chosen from `candidates` an **unlimited number of times**. Two combinations are unique if the frequency of at least one of the chosen numbers is different.\n\nThe test cases are generated such that the number of unique combinations that sum up to `target` is less than `150` combinations for the given input.",
10+
"_readme_examples": {
11+
"list": [
12+
{
13+
"content": "```\nInput: candidates = [2,3,6,7], target = 7\nOutput: [[2,2,3],[7]]\n```\n**Explanation:** 2 and 3 are candidates, and 2 + 2 + 3 = 7. Note that 2 can be used multiple times. 7 is a candidate, and 7 = 7. These are the only two combinations."
14+
},
15+
{
16+
"content": "```\nInput: candidates = [2,3,5], target = 8\nOutput: [[2,2,2,2],[2,3,3],[3,5]]\n```"
17+
},
18+
{ "content": "```\nInput: candidates = [2], target = 1\nOutput: []\n```" }
19+
]
20+
},
21+
"readme_constraints": "- 1 <= candidates.length <= 30\n- 2 <= candidates[i] <= 40\n- All elements of candidates are distinct.\n- 1 <= target <= 40",
22+
"readme_additional": "",
23+
"helpers_imports": "",
24+
"helpers_content": "",
25+
"helpers_run_name": "combination_sum",
26+
"helpers_run_signature": "(solution_class: type, candidates: list[int], target: int)",
27+
"helpers_run_body": " implementation = solution_class()\n return implementation.combination_sum(candidates, target)",
28+
"helpers_assert_name": "combination_sum",
29+
"helpers_assert_signature": "(result: list[list[int]], expected: list[list[int]]) -> bool",
30+
"helpers_assert_body": " # Sort both result and expected for comparison\n result_sorted = [sorted(combo) for combo in result]\n expected_sorted = [sorted(combo) for combo in expected]\n result_sorted.sort()\n expected_sorted.sort()\n assert result_sorted == expected_sorted\n return True",
31+
"solution_imports": "",
32+
"solution_contents": "",
33+
"solution_class_content": "",
34+
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .helpers import assert_combination_sum, run_combination_sum\nfrom .solution import Solution",
35+
"test_content": "",
36+
"test_class_name": "CombinationSum",
37+
"test_class_content": " def setup_method(self):\n self.solution = Solution()",
38+
"_solution_methods": {
39+
"list": [
40+
{
41+
"name": "combination_sum",
42+
"signature": "(self, candidates: list[int], target: int) -> list[list[int]]",
43+
"body": " # TODO: Implement combination_sum\n return []"
44+
}
45+
]
46+
},
47+
"_test_helper_methods": {
48+
"list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }]
49+
},
50+
"_test_methods": {
51+
"list": [
52+
{
53+
"name": "test_combination_sum",
54+
"signature": "(self, candidates: list[int], target: int, expected: list[list[int]])",
55+
"parametrize": "candidates, target, expected",
56+
"test_cases": "[([2, 3, 6, 7], 7, [[2, 2, 3], [7]]), ([2, 3, 5], 8, [[2, 2, 2, 2], [2, 3, 3], [3, 5]]), ([2], 1, [])]",
57+
"body": " result = run_combination_sum(Solution, candidates, target)\n assert_combination_sum(result, expected)"
58+
}
59+
]
60+
},
61+
"playground_imports": "from helpers import run_combination_sum, assert_combination_sum\nfrom solution import Solution",
62+
"playground_setup": "# Example test case\ncandidates = [2, 3, 6, 7]\ntarget = 7\nexpected = [[2, 2, 3], [7]]",
63+
"playground_run": "result = run_combination_sum(Solution, candidates, target)\nresult",
64+
"playground_assert": "assert_combination_sum(result, expected)"
65+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"problem_name": "container_with_most_water",
3+
"solution_class_name": "Solution",
4+
"problem_number": "11",
5+
"problem_title": "Container With Most Water",
6+
"difficulty": "Medium",
7+
"topics": "Array, Two Pointers, Greedy",
8+
"_tags": { "list": ["grind-75"] },
9+
"readme_description": "You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `i`th line are `(i, 0)` and `(i, height[i])`.\n\nFind two lines that together with the x-axis form a container, such that the container contains the most water.\n\nReturn the maximum amount of water a container can store.\n\nNotice that you may not slant the container.",
10+
"_readme_examples": {
11+
"list": [
12+
{
13+
"content": "![Example 1](https://s3-lc-upload.s3.amazonaws.com/uploads/2018/07/17/question_11.jpg)\n\n```\nInput: height = [1,8,6,2,5,4,8,3,7]\nOutput: 49\n```\n**Explanation:** The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49."
14+
},
15+
{ "content": "```\nInput: height = [1,1]\nOutput: 1\n```" }
16+
]
17+
},
18+
"readme_constraints": "- n == height.length\n- 2 <= n <= 10^5\n- 0 <= height[i] <= 10^4",
19+
"readme_additional": "",
20+
"helpers_imports": "",
21+
"helpers_content": "",
22+
"helpers_run_name": "max_area",
23+
"helpers_run_signature": "(solution_class: type, height: list[int])",
24+
"helpers_run_body": " implementation = solution_class()\n return implementation.max_area(height)",
25+
"helpers_assert_name": "max_area",
26+
"helpers_assert_signature": "(result: int, expected: int) -> bool",
27+
"helpers_assert_body": " assert result == expected\n return True",
28+
"solution_imports": "",
29+
"solution_contents": "",
30+
"solution_class_content": "",
31+
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .helpers import assert_max_area, run_max_area\nfrom .solution import Solution",
32+
"test_content": "",
33+
"test_class_name": "ContainerWithMostWater",
34+
"test_class_content": " def setup_method(self):\n self.solution = Solution()",
35+
"_solution_methods": {
36+
"list": [
37+
{
38+
"name": "max_area",
39+
"signature": "(self, height: list[int]) -> int",
40+
"body": " # TODO: Implement max_area\n return 0"
41+
}
42+
]
43+
},
44+
"_test_helper_methods": {
45+
"list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }]
46+
},
47+
"_test_methods": {
48+
"list": [
49+
{
50+
"name": "test_max_area",
51+
"signature": "(self, height: list[int], expected: int)",
52+
"parametrize": "height, expected",
53+
"test_cases": "[([1,8,6,2,5,4,8,3,7], 49), ([1,1], 1), ([1,2,1], 2)]",
54+
"body": " result = run_max_area(Solution, height)\n assert_max_area(result, expected)"
55+
}
56+
]
57+
},
58+
"playground_imports": "from helpers import run_max_area, assert_max_area\nfrom solution import Solution",
59+
"playground_setup": "# Example test case\nheight = [1,8,6,2,5,4,8,3,7]\nexpected = 49",
60+
"playground_run": "result = run_max_area(Solution, height)\nresult",
61+
"playground_assert": "assert_max_area(result, expected)"
62+
}

0 commit comments

Comments
 (0)