Skip to content

Commit 24eeece

Browse files
committed
feat: add zero_one_matrix
1 parent ca892d7 commit 24eeece

File tree

147 files changed

+5279
-0
lines changed

Some content is hidden

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

147 files changed

+5279
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"problem_name": "permutations",
3+
"solution_class_name": "Solution",
4+
"problem_number": "46",
5+
"problem_title": "Permutations",
6+
"difficulty": "Medium",
7+
"topics": "Array, Backtracking",
8+
"_tags": { "list": ["grind-75"] },
9+
"readme_description": "Given an array `nums` of distinct integers, return all the possible permutations. You can return the answer in any order.",
10+
"_readme_examples": {
11+
"list": [
12+
{
13+
"content": "```\nInput: nums = [1,2,3]\nOutput: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]\n```"
14+
},
15+
{ "content": "```\nInput: nums = [0,1]\nOutput: [[0,1],[1,0]]\n```" },
16+
{ "content": "```\nInput: nums = [1]\nOutput: [[1]]\n```" }
17+
]
18+
},
19+
"readme_constraints": "- 1 <= nums.length <= 6\n- -10 <= nums[i] <= 10\n- All the integers of nums are unique.",
20+
"readme_additional": "",
21+
"helpers_imports": "",
22+
"helpers_content": "",
23+
"helpers_run_name": "permute",
24+
"helpers_run_signature": "(solution_class: type, nums: list[int])",
25+
"helpers_run_body": " implementation = solution_class()\n return implementation.permute(nums)",
26+
"helpers_assert_name": "permute",
27+
"helpers_assert_signature": "(result: list[list[int]], expected: list[list[int]]) -> bool",
28+
"helpers_assert_body": " # Sort both result and expected for comparison since order doesn't matter\n result_sorted = [sorted(perm) for perm in result]\n expected_sorted = [sorted(perm) for perm in expected]\n result_sorted.sort()\n expected_sorted.sort()\n assert len(result) == len(expected)\n assert result_sorted == expected_sorted\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_permute, run_permute\nfrom .solution import Solution",
33+
"test_content": "",
34+
"test_class_name": "Permutations",
35+
"test_class_content": " def setup_method(self):\n self.solution = Solution()",
36+
"_solution_methods": {
37+
"list": [
38+
{
39+
"name": "permute",
40+
"signature": "(self, nums: list[int]) -> list[list[int]]",
41+
"body": " # TODO: Implement permute\n return []"
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_permute",
52+
"signature": "(self, nums: list[int], expected: list[list[int]])",
53+
"parametrize": "nums, expected",
54+
"test_cases": "[([1, 2, 3], [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]), ([0, 1], [[0, 1], [1, 0]]), ([1], [[1]]), ([2, 1], [[2, 1], [1, 2]])]",
55+
"body": " result = run_permute(Solution, nums)\n assert_permute(result, expected)"
56+
}
57+
]
58+
},
59+
"playground_imports": "from helpers import run_permute, assert_permute\nfrom solution import Solution",
60+
"playground_setup": "# Example test case\nnums = [1, 2, 3]\nexpected = [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]",
61+
"playground_run": "result = run_permute(Solution, nums)\nresult",
62+
"playground_assert": "assert_permute(result, expected)"
63+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"problem_name": "product_of_array_except_self",
3+
"solution_class_name": "Solution",
4+
"problem_number": "238",
5+
"problem_title": "Product of Array Except Self",
6+
"difficulty": "Medium",
7+
"topics": "Array, Prefix Sum",
8+
"_tags": { "list": ["grind-75"] },
9+
"readme_description": "Given an integer array `nums`, return an array `answer` such that `answer[i]` is equal to the product of all the elements of `nums` except `nums[i]`.\n\nThe product of any prefix or suffix of `nums` is guaranteed to fit in a 32-bit integer.\n\nYou must write an algorithm that runs in O(n) time and without using the division operation.",
10+
"_readme_examples": {
11+
"list": [
12+
{ "content": "```\nInput: nums = [1,2,3,4]\nOutput: [24,12,8,6]\n```" },
13+
{ "content": "```\nInput: nums = [-1,1,0,-3,3]\nOutput: [0,0,9,0,0]\n```" }
14+
]
15+
},
16+
"readme_constraints": "- 2 <= nums.length <= 10^5\n- -30 <= nums[i] <= 30\n- The input is generated such that answer[i] is guaranteed to fit in a 32-bit integer.",
17+
"readme_additional": "**Follow up:** Can you solve the problem in O(1) extra space complexity? (The output array does not count as extra space for space complexity analysis.)",
18+
"helpers_imports": "",
19+
"helpers_content": "",
20+
"helpers_run_name": "product_except_self",
21+
"helpers_run_signature": "(solution_class: type, nums: list[int])",
22+
"helpers_run_body": " implementation = solution_class()\n return implementation.product_except_self(nums)",
23+
"helpers_assert_name": "product_except_self",
24+
"helpers_assert_signature": "(result: list[int], expected: list[int]) -> bool",
25+
"helpers_assert_body": " assert result == expected\n return True",
26+
"solution_imports": "",
27+
"solution_contents": "",
28+
"solution_class_content": "",
29+
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .helpers import assert_product_except_self, run_product_except_self\nfrom .solution import Solution",
30+
"test_content": "",
31+
"test_class_name": "ProductOfArrayExceptSelf",
32+
"test_class_content": " def setup_method(self):\n self.solution = Solution()",
33+
"_solution_methods": {
34+
"list": [
35+
{
36+
"name": "product_except_self",
37+
"signature": "(self, nums: list[int]) -> list[int]",
38+
"body": " # TODO: Implement product_except_self\n return []"
39+
}
40+
]
41+
},
42+
"_test_helper_methods": {
43+
"list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }]
44+
},
45+
"_test_methods": {
46+
"list": [
47+
{
48+
"name": "test_product_except_self",
49+
"signature": "(self, nums: list[int], expected: list[int])",
50+
"parametrize": "nums, expected",
51+
"test_cases": "[([1, 2, 3, 4], [24, 12, 8, 6]), ([-1, 1, 0, -3, 3], [0, 0, 9, 0, 0]), ([2, 3, 4, 5], [60, 40, 30, 24]), ([1, 1], [1, 1]), ([5, 2], [2, 5]), ([0, 1, 2, 3], [6, 0, 0, 0]), ([1, 0, 3, 4], [0, 12, 0, 0])]",
52+
"body": " result = run_product_except_self(Solution, nums)\n assert_product_except_self(result, expected)"
53+
}
54+
]
55+
},
56+
"playground_imports": "from helpers import run_product_except_self, assert_product_except_self\nfrom solution import Solution",
57+
"playground_setup": "# Example test case\nnums = [1, 2, 3, 4]\nexpected = [24, 12, 8, 6]",
58+
"playground_run": "result = run_product_except_self(Solution, nums)\nresult",
59+
"playground_assert": "assert_product_except_self(result, expected)"
60+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"problem_name": "ransom_note",
3+
"solution_class_name": "Solution",
4+
"problem_number": "383",
5+
"problem_title": "Ransom Note",
6+
"difficulty": "Easy",
7+
"topics": "Hash Table, String, Counting",
8+
"_tags": { "list": ["grind-75"] },
9+
"readme_description": "Given two strings `ransomNote` and `magazine`, return `true` if `ransomNote` can be constructed by using the letters from `magazine` and `false` otherwise.\n\nEach letter in `magazine` can only be used once in `ransomNote`.",
10+
"_readme_examples": {
11+
"list": [
12+
{ "content": "```\nInput: ransomNote = \"a\", magazine = \"b\"\nOutput: false\n```" },
13+
{ "content": "```\nInput: ransomNote = \"aa\", magazine = \"ab\"\nOutput: false\n```" },
14+
{ "content": "```\nInput: ransomNote = \"aa\", magazine = \"aab\"\nOutput: true\n```" }
15+
]
16+
},
17+
"readme_constraints": "- 1 <= ransomNote.length, magazine.length <= 10^5\n- ransomNote and magazine consist of lowercase English letters.",
18+
"readme_additional": "",
19+
"helpers_imports": "",
20+
"helpers_content": "",
21+
"helpers_run_name": "can_construct",
22+
"helpers_run_signature": "(solution_class: type, ransom_note: str, magazine: str)",
23+
"helpers_run_body": " implementation = solution_class()\n return implementation.can_construct(ransom_note, magazine)",
24+
"helpers_assert_name": "can_construct",
25+
"helpers_assert_signature": "(result: bool, expected: bool) -> bool",
26+
"helpers_assert_body": " assert result == expected\n return True",
27+
"solution_imports": "",
28+
"solution_contents": "",
29+
"solution_class_content": "",
30+
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .helpers import assert_can_construct, run_can_construct\nfrom .solution import Solution",
31+
"test_content": "",
32+
"test_class_name": "RansomNote",
33+
"test_class_content": " def setup_method(self):\n self.solution = Solution()",
34+
"_solution_methods": {
35+
"list": [
36+
{
37+
"name": "can_construct",
38+
"signature": "(self, ransom_note: str, magazine: str) -> bool",
39+
"body": " # TODO: Implement can_construct\n return False"
40+
}
41+
]
42+
},
43+
"_test_helper_methods": {
44+
"list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }]
45+
},
46+
"_test_methods": {
47+
"list": [
48+
{
49+
"name": "test_can_construct",
50+
"signature": "(self, ransom_note: str, magazine: str, expected: bool)",
51+
"parametrize": "ransom_note, magazine, expected",
52+
"test_cases": "[('a', 'b', False), ('aa', 'ab', False), ('aa', 'aab', True), ('aab', 'baa', True), ('', '', True), ('', 'abc', True), ('abc', '', False), ('abc', 'abc', True), ('abc', 'cba', True), ('aaa', 'aa', False), ('ab', 'ba', True)]",
53+
"body": " result = run_can_construct(Solution, ransom_note, magazine)\n assert_can_construct(result, expected)"
54+
}
55+
]
56+
},
57+
"playground_imports": "from helpers import run_can_construct, assert_can_construct\nfrom solution import Solution",
58+
"playground_setup": "# Example test case\nransom_note = 'aa'\nmagazine = 'aab'\nexpected = True",
59+
"playground_run": "result = run_can_construct(Solution, ransom_note, magazine)\nresult",
60+
"playground_assert": "assert_can_construct(result, expected)"
61+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"problem_name": "reverse_linked_list",
3+
"solution_class_name": "Solution",
4+
"problem_number": "206",
5+
"problem_title": "Reverse Linked List",
6+
"difficulty": "Easy",
7+
"topics": "Linked List, Recursion",
8+
"_tags": { "list": ["grind-75"] },
9+
"readme_description": "Given the `head` of a singly linked list, reverse the list, and return the reversed list.",
10+
"_readme_examples": {
11+
"list": [
12+
{
13+
"content": "![Example 1](https://assets.leetcode.com/uploads/2021/02/19/rev1ex1.jpg)\n\n```\nInput: head = [1,2,3,4,5]\nOutput: [5,4,3,2,1]\n```"
14+
},
15+
{
16+
"content": "![Example 2](https://assets.leetcode.com/uploads/2021/02/19/rev1ex2.jpg)\n\n```\nInput: head = [1,2]\nOutput: [2,1]\n```"
17+
},
18+
{ "content": "```\nInput: head = []\nOutput: []\n```" }
19+
]
20+
},
21+
"readme_constraints": "- The number of nodes in the list is the range `[0, 5000]`.\n- `-5000 <= Node.val <= 5000`",
22+
"readme_additional": "**Follow up:** A linked list can be reversed either iteratively or recursively. Could you implement both?",
23+
"helpers_imports": "from leetcode_py import ListNode",
24+
"helpers_content": "",
25+
"helpers_run_name": "reverse_list",
26+
"helpers_run_signature": "(solution_class: type, head_list: list[int])",
27+
"helpers_run_body": " head = ListNode[int].from_list(head_list)\n implementation = solution_class()\n return implementation.reverse_list(head)",
28+
"helpers_assert_name": "reverse_list",
29+
"helpers_assert_signature": "(result: ListNode[int] | None, expected_list: list[int]) -> bool",
30+
"helpers_assert_body": " expected = ListNode[int].from_list(expected_list)\n assert result == expected\n return True",
31+
"solution_imports": "from leetcode_py import ListNode",
32+
"solution_contents": "",
33+
"solution_class_content": "",
34+
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .helpers import assert_reverse_list, run_reverse_list\nfrom .solution import Solution",
35+
"test_content": "",
36+
"test_class_name": "ReverseLinkedList",
37+
"test_class_content": " def setup_method(self):\n self.solution = Solution()",
38+
"_solution_methods": {
39+
"list": [
40+
{
41+
"name": "reverse_list",
42+
"signature": "(self, head: ListNode[int] | None) -> ListNode[int] | None",
43+
"body": " # TODO: Implement reverse_list\n return None"
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_reverse_list",
54+
"signature": "(self, head_list: list[int], expected_list: list[int])",
55+
"parametrize": "head_list, expected_list",
56+
"test_cases": "[([1, 2, 3, 4, 5], [5, 4, 3, 2, 1]), ([1, 2], [2, 1]), ([1], [1]), ([], []), ([1, 2, 3], [3, 2, 1]), ([1, 2, 3, 4], [4, 3, 2, 1]), ([-1, -2, -3], [-3, -2, -1]), ([0], [0]), ([5000, -5000], [-5000, 5000]), ([1, 1, 1], [1, 1, 1])]",
57+
"body": " result = run_reverse_list(Solution, head_list)\n assert_reverse_list(result, expected_list)"
58+
}
59+
]
60+
},
61+
"playground_imports": "from helpers import run_reverse_list, assert_reverse_list\nfrom solution import Solution\nfrom leetcode_py import ListNode",
62+
"playground_setup": "# Example test case\nhead_list = [1, 2, 3, 4, 5]\nexpected_list = [5, 4, 3, 2, 1]",
63+
"playground_run": "result = run_reverse_list(Solution, head_list)\nresult",
64+
"playground_assert": "assert_reverse_list(result, expected_list)"
65+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"problem_name": "reverse_linked_list_ii",
3+
"solution_class_name": "Solution",
4+
"problem_number": "92",
5+
"problem_title": "Reverse Linked List II",
6+
"difficulty": "Medium",
7+
"topics": "Linked List",
8+
"_tags": { "list": [] },
9+
"readme_description": "Given the `head` of a singly linked list and two integers `left` and `right` where `left <= right`, reverse the nodes of the list from position `left` to position `right`, and return the reversed list.",
10+
"_readme_examples": {
11+
"list": [
12+
{
13+
"content": "```\nInput: head = [1,2,3,4,5], left = 2, right = 4\nOutput: [1,4,3,2,5]\n```"
14+
},
15+
{ "content": "```\nInput: head = [5], left = 1, right = 1\nOutput: [5]\n```" }
16+
]
17+
},
18+
"readme_constraints": "- The number of nodes in the list is n\n- 1 <= n <= 500\n- -500 <= Node.val <= 500\n- 1 <= left <= right <= n",
19+
"readme_additional": "**Follow up:** Could you do it in one pass?",
20+
"helpers_imports": "from leetcode_py import ListNode",
21+
"helpers_content": "",
22+
"helpers_run_name": "reverse_between",
23+
"helpers_run_signature": "(solution_class: type, head_list: list[int], left: int, right: int)",
24+
"helpers_run_body": " head = ListNode[int].from_list(head_list)\n implementation = solution_class()\n return implementation.reverse_between(head, left, right)",
25+
"helpers_assert_name": "reverse_between",
26+
"helpers_assert_signature": "(result: ListNode[int] | None, expected_list: list[int]) -> bool",
27+
"helpers_assert_body": " expected = ListNode[int].from_list(expected_list)\n assert result == expected\n return True",
28+
"solution_imports": "from leetcode_py import ListNode",
29+
"solution_contents": "",
30+
"solution_class_content": "",
31+
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .helpers import assert_reverse_between, run_reverse_between\nfrom .solution import Solution",
32+
"test_content": "",
33+
"test_class_name": "ReverseLinkedListII",
34+
"test_class_content": " def setup_method(self):\n self.solution = Solution()",
35+
"_solution_methods": {
36+
"list": [
37+
{
38+
"name": "reverse_between",
39+
"signature": "(self, head: ListNode[int] | None, left: int, right: int) -> ListNode[int] | None",
40+
"body": " # TODO: Implement reverse_between\n return None"
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_reverse_between",
51+
"signature": "(self, head_list: list[int], left: int, right: int, expected_list: list[int])",
52+
"parametrize": "head_list, left, right, expected_list",
53+
"test_cases": "[([1, 2, 3, 4, 5], 2, 4, [1, 4, 3, 2, 5]), ([5], 1, 1, [5]), ([1, 2], 1, 2, [2, 1]), ([1, 2, 3], 1, 3, [3, 2, 1]), ([1, 2, 3, 4, 5], 1, 5, [5, 4, 3, 2, 1]), ([1, 2, 3, 4, 5], 3, 3, [1, 2, 3, 4, 5])]",
54+
"body": " result = run_reverse_between(Solution, head_list, left, right)\n assert_reverse_between(result, expected_list)"
55+
}
56+
]
57+
},
58+
"playground_imports": "from helpers import run_reverse_between, assert_reverse_between\nfrom solution import Solution\nfrom leetcode_py import ListNode",
59+
"playground_setup": "# Example test case\nhead_list = [1, 2, 3, 4, 5]\nleft, right = 2, 4\nexpected_list = [1, 4, 3, 2, 5]",
60+
"playground_run": "result = run_reverse_between(Solution, head_list, left, right)\nresult",
61+
"playground_assert": "assert_reverse_between(result, expected_list)"
62+
}

0 commit comments

Comments
 (0)