Skip to content

Commit b2e7035

Browse files
authored
feat: add more grind-75 problems (#26)
1 parent e810c96 commit b2e7035

Some content is hidden

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

41 files changed

+1692
-14
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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": ["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+
{
12+
"content": "```\nInput: coins = [1,2,5], amount = 11\nOutput: 3\n```\n**Explanation:** 11 = 5 + 5 + 1"
13+
},
14+
{ "content": "```\nInput: coins = [2], amount = 3\nOutput: -1\n```" },
15+
{ "content": "```\nInput: coins = [1], amount = 0\nOutput: 0\n```" }
16+
],
17+
"readme_constraints": "- `1 <= coins.length <= 12`\n- `1 <= coins[i] <= 2^31 - 1`\n- `0 <= amount <= 10^4`",
18+
"readme_additional": "",
19+
"solution_imports": "",
20+
"solution_methods": [
21+
{
22+
"name": "coin_change",
23+
"parameters": "coins: list[int], amount: int",
24+
"return_type": "int",
25+
"dummy_return": "-1"
26+
}
27+
],
28+
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution",
29+
"test_class_name": "CoinChange",
30+
"test_helper_methods": [
31+
{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }
32+
],
33+
"test_methods": [
34+
{
35+
"name": "test_coin_change",
36+
"parametrize": "coins, amount, expected",
37+
"parametrize_typed": "coins: list[int], amount: int, expected: int",
38+
"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)]",
39+
"body": "result = self.solution.coin_change(coins, amount)\nassert result == expected"
40+
}
41+
],
42+
"playground_imports": "from solution import Solution",
43+
"playground_test_case": "# Example test case\ncoins = [1, 2, 5]\namount = 11\nexpected = 3",
44+
"playground_execution": "result = Solution().coin_change(coins, amount)\nresult",
45+
"playground_assertion": "assert result == expected"
46+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"problem_name": "largest_rectangle_in_histogram",
3+
"solution_class_name": "Solution",
4+
"problem_number": "84",
5+
"problem_title": "Largest Rectangle in Histogram",
6+
"difficulty": "Hard",
7+
"topics": "Array, Stack, Monotonic Stack",
8+
"tags": ["grind-75"],
9+
"readme_description": "Given an array of integers `heights` representing the histogram's bar height where the width of each bar is `1`, return the area of the largest rectangle in the histogram.",
10+
"readme_examples": [
11+
{
12+
"content": "![Example 1](https://assets.leetcode.com/uploads/2021/01/04/histogram.jpg)\n\n```\nInput: heights = [2,1,5,6,2,3]\nOutput: 10\n```\n**Explanation:** The above is a histogram where width of each bar is 1. The largest rectangle is shown in the red area, which has an area = 10 units."
13+
},
14+
{
15+
"content": "![Example 2](https://assets.leetcode.com/uploads/2021/01/04/histogram-1.jpg)\n\n```\nInput: heights = [2,4]\nOutput: 4\n```"
16+
}
17+
],
18+
"readme_constraints": "- `1 <= heights.length <= 10^5`\n- `0 <= heights[i] <= 10^4`",
19+
"readme_additional": "",
20+
"solution_imports": "",
21+
"solution_methods": [
22+
{
23+
"name": "largest_rectangle_area",
24+
"parameters": "heights: list[int]",
25+
"return_type": "int",
26+
"dummy_return": "0"
27+
}
28+
],
29+
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution",
30+
"test_class_name": "LargestRectangleInHistogram",
31+
"test_helper_methods": [
32+
{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }
33+
],
34+
"test_methods": [
35+
{
36+
"name": "test_largest_rectangle_area",
37+
"parametrize": "heights, expected",
38+
"parametrize_typed": "heights: list[int], expected: int",
39+
"test_cases": "[([2, 1, 5, 6, 2, 3], 10), ([2, 4], 4), ([1], 1), ([0], 0), ([1, 1], 2), ([0, 0, 0], 0), ([1, 2, 3, 4, 5], 9), ([5, 4, 3, 2, 1], 9), ([3, 3, 3, 3], 12), ([2, 1, 2], 3), ([1, 3, 1], 3), ([6, 7, 5, 2, 4, 5, 9, 3], 16), ([4, 2, 0, 3, 2, 5], 6), ([1, 2, 2, 1], 4), ([0, 9], 9), ([9, 0], 9), ([2, 1, 5, 6, 2, 3, 1, 5, 6, 2], 10), ([1, 8, 6, 2, 5, 4, 8, 3, 7], 16)]",
40+
"body": "result = self.solution.largest_rectangle_area(heights)\nassert result == expected"
41+
}
42+
],
43+
"playground_imports": "from solution import Solution",
44+
"playground_test_case": "# Example test case\nheights = [2, 1, 5, 6, 2, 3]\nexpected = 10",
45+
"playground_execution": "result = Solution().largest_rectangle_area(heights)\nresult",
46+
"playground_assertion": "assert result == expected"
47+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"problem_name": "maximum_profit_in_job_scheduling",
3+
"solution_class_name": "Solution",
4+
"problem_number": "1235",
5+
"problem_title": "Maximum Profit in Job Scheduling",
6+
"difficulty": "Hard",
7+
"topics": "Array, Binary Search, Dynamic Programming, Sorting",
8+
"tags": ["grind-75"],
9+
"readme_description": "We have `n` jobs, where every job is scheduled to be done from `startTime[i]` to `endTime[i]`, obtaining a profit of `profit[i]`.\n\nYou're given the `startTime`, `endTime` and `profit` arrays, return the maximum profit you can take such that there are no two jobs in the subset with overlapping time range.\n\nIf you choose a job that ends at time `X` you will be able to start another job that starts at time `X`.",
10+
"readme_examples": [
11+
{
12+
"content": "![Example 1](https://assets.leetcode.com/uploads/2019/10/10/sample1_1584.png)\n\n```\nInput: startTime = [1,2,3,3], endTime = [3,4,5,6], profit = [50,10,40,70]\nOutput: 120\n```\n**Explanation:** The subset chosen is the first and fourth job. Time range [1-3]+[3-6] , we get profit of 120 = 50 + 70."
13+
},
14+
{
15+
"content": "![Example 2](https://assets.leetcode.com/uploads/2019/10/10/sample22_1584.png)\n\n```\nInput: startTime = [1,2,3,4,6], endTime = [3,5,10,6,9], profit = [20,20,100,70,60]\nOutput: 150\n```\n**Explanation:** The subset chosen is the first, fourth and fifth job. Profit obtained 150 = 20 + 70 + 60."
16+
},
17+
{
18+
"content": "![Example 3](https://assets.leetcode.com/uploads/2019/10/10/sample3_1584.png)\n\n```\nInput: startTime = [1,1,1], endTime = [2,3,4], profit = [5,6,4]\nOutput: 6\n```"
19+
}
20+
],
21+
"readme_constraints": "- `1 <= startTime.length == endTime.length == profit.length <= 5 * 10^4`\n- `1 <= startTime[i] < endTime[i] <= 10^9`\n- `1 <= profit[i] <= 10^4`",
22+
"readme_additional": "",
23+
"solution_imports": "",
24+
"solution_methods": [
25+
{
26+
"name": "job_scheduling",
27+
"parameters": "start_time: list[int], end_time: list[int], profit: list[int]",
28+
"return_type": "int",
29+
"dummy_return": "0"
30+
}
31+
],
32+
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution",
33+
"test_class_name": "MaximumProfitInJobScheduling",
34+
"test_helper_methods": [
35+
{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }
36+
],
37+
"test_methods": [
38+
{
39+
"name": "test_job_scheduling",
40+
"parametrize": "start_time, end_time, profit, expected",
41+
"parametrize_typed": "start_time: list[int], end_time: list[int], profit: list[int], expected: int",
42+
"test_cases": "[([1, 2, 3, 3], [3, 4, 5, 6], [50, 10, 40, 70], 120), ([1, 2, 3, 4, 6], [3, 5, 10, 6, 9], [20, 20, 100, 70, 60], 150), ([1, 1, 1], [2, 3, 4], [5, 6, 4], 6)]",
43+
"body": "result = self.solution.job_scheduling(start_time, end_time, profit)\nassert result == expected"
44+
}
45+
],
46+
"playground_imports": "from solution import Solution",
47+
"playground_test_case": "# Example test case\nstart_time = [1, 2, 3, 3]\nend_time = [3, 4, 5, 6]\nprofit = [50, 10, 40, 70]\nexpected = 120",
48+
"playground_execution": "result = Solution().job_scheduling(start_time, end_time, profit)\nresult",
49+
"playground_assertion": "assert result == expected"
50+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"problem_name": "merge_intervals",
3+
"solution_class_name": "Solution",
4+
"problem_number": "56",
5+
"problem_title": "Merge Intervals",
6+
"difficulty": "Medium",
7+
"topics": "Array, Sorting",
8+
"tags": ["grind-75"],
9+
"readme_description": "Given an array of `intervals` where `intervals[i] = [starti, endi]`, merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.",
10+
"readme_examples": [
11+
{
12+
"content": "```\nInput: intervals = [[1,3],[2,6],[8,10],[15,18]]\nOutput: [[1,6],[8,10],[15,18]]\n```\n**Explanation:** Since intervals [1,3] and [2,6] overlap, merge them into [1,6]."
13+
},
14+
{
15+
"content": "```\nInput: intervals = [[1,4],[4,5]]\nOutput: [[1,5]]\n```\n**Explanation:** Intervals [1,4] and [4,5] are considered overlapping."
16+
},
17+
{
18+
"content": "```\nInput: intervals = [[4,7],[1,4]]\nOutput: [[1,7]]\n```\n**Explanation:** Intervals [1,4] and [4,7] are considered overlapping."
19+
}
20+
],
21+
"readme_constraints": "- `1 <= intervals.length <= 10^4`\n- `intervals[i].length == 2`\n- `0 <= starti <= endi <= 10^4`",
22+
"readme_additional": "",
23+
"solution_imports": "",
24+
"solution_methods": [
25+
{
26+
"name": "merge",
27+
"parameters": "intervals: list[list[int]]",
28+
"return_type": "list[list[int]]",
29+
"dummy_return": "[]"
30+
}
31+
],
32+
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution",
33+
"test_class_name": "MergeIntervals",
34+
"test_helper_methods": [
35+
{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }
36+
],
37+
"test_methods": [
38+
{
39+
"name": "test_merge",
40+
"parametrize": "intervals, expected",
41+
"parametrize_typed": "intervals: list[list[int]], expected: list[list[int]]",
42+
"test_cases": "[([[1,3],[2,6],[8,10],[15,18]], [[1,6],[8,10],[15,18]]), ([[1,4],[4,5]], [[1,5]]), ([[4,7],[1,4]], [[1,7]])]",
43+
"body": "result = self.solution.merge(intervals)\nassert result == expected"
44+
}
45+
],
46+
"playground_imports": "from solution import Solution",
47+
"playground_test_case": "# Example test case\nintervals = [[1,3],[2,6],[8,10],[15,18]]\nexpected = [[1,6],[8,10],[15,18]]",
48+
"playground_execution": "result = Solution().merge(intervals)\nresult",
49+
"playground_assertion": "assert result == expected"
50+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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": ["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+
{
12+
"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```"
13+
},
14+
{
15+
"content": "![Example 2](https://assets.leetcode.com/uploads/2021/02/19/rev1ex2.jpg)\n\n```\nInput: head = [1,2]\nOutput: [2,1]\n```"
16+
},
17+
{ "content": "```\nInput: head = []\nOutput: []\n```" }
18+
],
19+
"readme_constraints": "- The number of nodes in the list is the range `[0, 5000]`.\n- `-5000 <= Node.val <= 5000`",
20+
"readme_additional": "**Follow up:** A linked list can be reversed either iteratively or recursively. Could you implement both?",
21+
"solution_imports": "from leetcode_py import ListNode",
22+
"solution_methods": [
23+
{
24+
"name": "reverse_list",
25+
"parameters": "head: ListNode[int] | None",
26+
"return_type": "ListNode[int] | None",
27+
"dummy_return": "None"
28+
}
29+
],
30+
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom leetcode_py import ListNode\nfrom .solution import Solution",
31+
"test_class_name": "ReverseLinkedList",
32+
"test_helper_methods": [
33+
{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }
34+
],
35+
"test_methods": [
36+
{
37+
"name": "test_reverse_list",
38+
"parametrize": "head_list, expected_list",
39+
"parametrize_typed": "head_list: list[int], expected_list: list[int]",
40+
"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])]",
41+
"body": "head = ListNode.from_list(head_list)\nexpected = ListNode.from_list(expected_list)\nresult = self.solution.reverse_list(head)\nassert result == expected"
42+
}
43+
],
44+
"playground_imports": "from leetcode_py import ListNode\nfrom solution import Solution",
45+
"playground_test_case": "# Example test case\nhead_list = [1, 2, 3, 4, 5]\nexpected_list = [5, 4, 3, 2, 1]\nhead = ListNode.from_list(head_list)\nexpected = ListNode.from_list(expected_list)",
46+
"playground_execution": "result = Solution().reverse_list(head)\nresult",
47+
"playground_assertion": "assert result == expected"
48+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"problem_name": "trapping_rain_water",
3+
"solution_class_name": "Solution",
4+
"problem_number": "42",
5+
"problem_title": "Trapping Rain Water",
6+
"difficulty": "Hard",
7+
"topics": "Array, Two Pointers, Dynamic Programming, Stack, Monotonic Stack",
8+
"tags": ["grind-75"],
9+
"readme_description": "Given `n` non-negative integers representing an elevation map where the width of each bar is `1`, compute how much water it can trap after raining.",
10+
"readme_examples": [
11+
{
12+
"content": "![Example 1](https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png)\n\n```\nInput: height = [0,1,0,2,1,0,1,3,2,1,2,1]\nOutput: 6\n```\n**Explanation:** The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped."
13+
},
14+
{ "content": "```\nInput: height = [4,2,0,3,2,5]\nOutput: 9\n```" }
15+
],
16+
"readme_constraints": "- `n == height.length`\n- `1 <= n <= 2 * 10^4`\n- `0 <= height[i] <= 10^5`",
17+
"readme_additional": "",
18+
"solution_imports": "",
19+
"solution_methods": [
20+
{ "name": "trap", "parameters": "height: list[int]", "return_type": "int", "dummy_return": "0" }
21+
],
22+
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution",
23+
"test_class_name": "TrappingRainWater",
24+
"test_helper_methods": [
25+
{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }
26+
],
27+
"test_methods": [
28+
{
29+
"name": "test_trap",
30+
"parametrize": "height, expected",
31+
"parametrize_typed": "height: list[int], expected: int",
32+
"test_cases": "[([0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1], 6), ([4, 2, 0, 3, 2, 5], 9), ([3, 0, 2, 0, 4], 7), ([0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1], 6)]",
33+
"body": "result = self.solution.trap(height)\nassert result == expected"
34+
}
35+
],
36+
"playground_imports": "from solution import Solution",
37+
"playground_test_case": "# Example test case\nheight = [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]\nexpected = 6",
38+
"playground_execution": "result = Solution().trap(height)\nresult",
39+
"playground_assertion": "assert result == expected"
40+
}

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PYTHON_VERSION = 3.13
2-
PROBLEM ?= longest_palindrome
2+
PROBLEM ?= maximum_profit_in_job_scheduling
33
FORCE ?= 0
44
COMMA := ,
55

leetcode/coin_change/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Coin Change
2+
3+
**Difficulty:** Medium
4+
**Topics:** Array, Dynamic Programming, Breadth-First Search
5+
**Tags:** grind-75
6+
7+
**LeetCode:** [Problem 322](https://leetcode.com/problems/coin-change/description/)
8+
9+
## Problem Description
10+
11+
You are given an integer array `coins` representing coins of different denominations and an integer `amount` representing a total amount of money.
12+
13+
Return 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`.
14+
15+
You may assume that you have an infinite number of each kind of coin.
16+
17+
## Examples
18+
19+
### Example 1:
20+
21+
```
22+
Input: coins = [1,2,5], amount = 11
23+
Output: 3
24+
```
25+
26+
**Explanation:** 11 = 5 + 5 + 1
27+
28+
### Example 2:
29+
30+
```
31+
Input: coins = [2], amount = 3
32+
Output: -1
33+
```
34+
35+
### Example 3:
36+
37+
```
38+
Input: coins = [1], amount = 0
39+
Output: 0
40+
```
41+
42+
## Constraints
43+
44+
- `1 <= coins.length <= 12`
45+
- `1 <= coins[i] <= 2^31 - 1`
46+
- `0 <= amount <= 10^4`

leetcode/coin_change/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)