Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
46 changes: 46 additions & 0 deletions .templates/leetcode/json/coin_change.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"problem_name": "coin_change",
"solution_class_name": "Solution",
"problem_number": "322",
"problem_title": "Coin Change",
"difficulty": "Medium",
"topics": "Array, Dynamic Programming, Breadth-First Search",
"tags": ["grind-75"],
"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.",
"readme_examples": [
{
"content": "```\nInput: coins = [1,2,5], amount = 11\nOutput: 3\n```\n**Explanation:** 11 = 5 + 5 + 1"
},
{ "content": "```\nInput: coins = [2], amount = 3\nOutput: -1\n```" },
{ "content": "```\nInput: coins = [1], amount = 0\nOutput: 0\n```" }
],
"readme_constraints": "- `1 <= coins.length <= 12`\n- `1 <= coins[i] <= 2^31 - 1`\n- `0 <= amount <= 10^4`",
"readme_additional": "",
"solution_imports": "",
"solution_methods": [
{
"name": "coin_change",
"parameters": "coins: list[int], amount: int",
"return_type": "int",
"dummy_return": "-1"
}
],
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution",
"test_class_name": "CoinChange",
"test_helper_methods": [
{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }
],
"test_methods": [
{
"name": "test_coin_change",
"parametrize": "coins, amount, expected",
"parametrize_typed": "coins: list[int], amount: int, expected: int",
"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)]",
"body": "result = self.solution.coin_change(coins, amount)\nassert result == expected"
}
],
"playground_imports": "from solution import Solution",
"playground_test_case": "# Example test case\ncoins = [1, 2, 5]\namount = 11\nexpected = 3",
"playground_execution": "result = Solution().coin_change(coins, amount)\nresult",
"playground_assertion": "assert result == expected"
}
47 changes: 47 additions & 0 deletions .templates/leetcode/json/largest_rectangle_in_histogram.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"problem_name": "largest_rectangle_in_histogram",
"solution_class_name": "Solution",
"problem_number": "84",
"problem_title": "Largest Rectangle in Histogram",
"difficulty": "Hard",
"topics": "Array, Stack, Monotonic Stack",
"tags": ["grind-75"],
"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.",
"readme_examples": [
{
"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."
},
{
"content": "![Example 2](https://assets.leetcode.com/uploads/2021/01/04/histogram-1.jpg)\n\n```\nInput: heights = [2,4]\nOutput: 4\n```"
}
],
"readme_constraints": "- `1 <= heights.length <= 10^5`\n- `0 <= heights[i] <= 10^4`",
"readme_additional": "",
"solution_imports": "",
"solution_methods": [
{
"name": "largest_rectangle_area",
"parameters": "heights: list[int]",
"return_type": "int",
"dummy_return": "0"
}
],
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution",
"test_class_name": "LargestRectangleInHistogram",
"test_helper_methods": [
{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }
],
"test_methods": [
{
"name": "test_largest_rectangle_area",
"parametrize": "heights, expected",
"parametrize_typed": "heights: list[int], expected: int",
"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)]",
"body": "result = self.solution.largest_rectangle_area(heights)\nassert result == expected"
}
],
"playground_imports": "from solution import Solution",
"playground_test_case": "# Example test case\nheights = [2, 1, 5, 6, 2, 3]\nexpected = 10",
"playground_execution": "result = Solution().largest_rectangle_area(heights)\nresult",
"playground_assertion": "assert result == expected"
}
50 changes: 50 additions & 0 deletions .templates/leetcode/json/maximum_profit_in_job_scheduling.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"problem_name": "maximum_profit_in_job_scheduling",
"solution_class_name": "Solution",
"problem_number": "1235",
"problem_title": "Maximum Profit in Job Scheduling",
"difficulty": "Hard",
"topics": "Array, Binary Search, Dynamic Programming, Sorting",
"tags": ["grind-75"],
"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`.",
"readme_examples": [
{
"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."
},
{
"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."
},
{
"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```"
}
],
"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`",
"readme_additional": "",
"solution_imports": "",
"solution_methods": [
{
"name": "job_scheduling",
"parameters": "start_time: list[int], end_time: list[int], profit: list[int]",
"return_type": "int",
"dummy_return": "0"
}
],
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution",
"test_class_name": "MaximumProfitInJobScheduling",
"test_helper_methods": [
{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }
],
"test_methods": [
{
"name": "test_job_scheduling",
"parametrize": "start_time, end_time, profit, expected",
"parametrize_typed": "start_time: list[int], end_time: list[int], profit: list[int], expected: int",
"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)]",
"body": "result = self.solution.job_scheduling(start_time, end_time, profit)\nassert result == expected"
}
],
"playground_imports": "from solution import Solution",
"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",
"playground_execution": "result = Solution().job_scheduling(start_time, end_time, profit)\nresult",
"playground_assertion": "assert result == expected"
}
50 changes: 50 additions & 0 deletions .templates/leetcode/json/merge_intervals.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"problem_name": "merge_intervals",
"solution_class_name": "Solution",
"problem_number": "56",
"problem_title": "Merge Intervals",
"difficulty": "Medium",
"topics": "Array, Sorting",
"tags": ["grind-75"],
"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.",
"readme_examples": [
{
"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]."
},
{
"content": "```\nInput: intervals = [[1,4],[4,5]]\nOutput: [[1,5]]\n```\n**Explanation:** Intervals [1,4] and [4,5] are considered overlapping."
},
{
"content": "```\nInput: intervals = [[4,7],[1,4]]\nOutput: [[1,7]]\n```\n**Explanation:** Intervals [1,4] and [4,7] are considered overlapping."
}
],
"readme_constraints": "- `1 <= intervals.length <= 10^4`\n- `intervals[i].length == 2`\n- `0 <= starti <= endi <= 10^4`",
"readme_additional": "",
"solution_imports": "",
"solution_methods": [
{
"name": "merge",
"parameters": "intervals: list[list[int]]",
"return_type": "list[list[int]]",
"dummy_return": "[]"
}
],
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution",
"test_class_name": "MergeIntervals",
"test_helper_methods": [
{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }
],
"test_methods": [
{
"name": "test_merge",
"parametrize": "intervals, expected",
"parametrize_typed": "intervals: list[list[int]], expected: list[list[int]]",
"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]])]",
"body": "result = self.solution.merge(intervals)\nassert result == expected"
}
],
"playground_imports": "from solution import Solution",
"playground_test_case": "# Example test case\nintervals = [[1,3],[2,6],[8,10],[15,18]]\nexpected = [[1,6],[8,10],[15,18]]",
"playground_execution": "result = Solution().merge(intervals)\nresult",
"playground_assertion": "assert result == expected"
}
48 changes: 48 additions & 0 deletions .templates/leetcode/json/reverse_linked_list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"problem_name": "reverse_linked_list",
"solution_class_name": "Solution",
"problem_number": "206",
"problem_title": "Reverse Linked List",
"difficulty": "Easy",
"topics": "Linked List, Recursion",
"tags": ["grind-75"],
"readme_description": "Given the `head` of a singly linked list, reverse the list, and return the reversed list.",
"readme_examples": [
{
"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```"
},
{
"content": "![Example 2](https://assets.leetcode.com/uploads/2021/02/19/rev1ex2.jpg)\n\n```\nInput: head = [1,2]\nOutput: [2,1]\n```"
},
{ "content": "```\nInput: head = []\nOutput: []\n```" }
],
"readme_constraints": "- The number of nodes in the list is the range `[0, 5000]`.\n- `-5000 <= Node.val <= 5000`",
"readme_additional": "**Follow up:** A linked list can be reversed either iteratively or recursively. Could you implement both?",
"solution_imports": "from leetcode_py import ListNode",
"solution_methods": [
{
"name": "reverse_list",
"parameters": "head: ListNode[int] | None",
"return_type": "ListNode[int] | None",
"dummy_return": "None"
}
],
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom leetcode_py import ListNode\nfrom .solution import Solution",
"test_class_name": "ReverseLinkedList",
"test_helper_methods": [
{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }
],
"test_methods": [
{
"name": "test_reverse_list",
"parametrize": "head_list, expected_list",
"parametrize_typed": "head_list: list[int], expected_list: list[int]",
"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])]",
"body": "head = ListNode.from_list(head_list)\nexpected = ListNode.from_list(expected_list)\nresult = self.solution.reverse_list(head)\nassert result == expected"
}
],
"playground_imports": "from leetcode_py import ListNode\nfrom solution import Solution",
"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)",
"playground_execution": "result = Solution().reverse_list(head)\nresult",
"playground_assertion": "assert result == expected"
}
40 changes: 40 additions & 0 deletions .templates/leetcode/json/trapping_rain_water.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"problem_name": "trapping_rain_water",
"solution_class_name": "Solution",
"problem_number": "42",
"problem_title": "Trapping Rain Water",
"difficulty": "Hard",
"topics": "Array, Two Pointers, Dynamic Programming, Stack, Monotonic Stack",
"tags": ["grind-75"],
"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.",
"readme_examples": [
{
"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."
},
{ "content": "```\nInput: height = [4,2,0,3,2,5]\nOutput: 9\n```" }
],
"readme_constraints": "- `n == height.length`\n- `1 <= n <= 2 * 10^4`\n- `0 <= height[i] <= 10^5`",
"readme_additional": "",
"solution_imports": "",
"solution_methods": [
{ "name": "trap", "parameters": "height: list[int]", "return_type": "int", "dummy_return": "0" }
],
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution",
"test_class_name": "TrappingRainWater",
"test_helper_methods": [
{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }
],
"test_methods": [
{
"name": "test_trap",
"parametrize": "height, expected",
"parametrize_typed": "height: list[int], expected: int",
"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)]",
"body": "result = self.solution.trap(height)\nassert result == expected"
}
],
"playground_imports": "from solution import Solution",
"playground_test_case": "# Example test case\nheight = [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]\nexpected = 6",
"playground_execution": "result = Solution().trap(height)\nresult",
"playground_assertion": "assert result == expected"
}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PYTHON_VERSION = 3.13
PROBLEM ?= longest_palindrome
PROBLEM ?= maximum_profit_in_job_scheduling
FORCE ?= 0
COMMA := ,

Expand Down
46 changes: 46 additions & 0 deletions leetcode/coin_change/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Coin Change

**Difficulty:** Medium
**Topics:** Array, Dynamic Programming, Breadth-First Search
**Tags:** grind-75

**LeetCode:** [Problem 322](https://leetcode.com/problems/coin-change/description/)

## Problem Description

You are given an integer array `coins` representing coins of different denominations and an integer `amount` representing a total amount of money.

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`.

You may assume that you have an infinite number of each kind of coin.

## Examples

### Example 1:

```
Input: coins = [1,2,5], amount = 11
Output: 3
```

**Explanation:** 11 = 5 + 5 + 1

### Example 2:

```
Input: coins = [2], amount = 3
Output: -1
```

### Example 3:

```
Input: coins = [1], amount = 0
Output: 0
```

## Constraints

- `1 <= coins.length <= 12`
- `1 <= coins[i] <= 2^31 - 1`
- `0 <= amount <= 10^4`
Empty file.
Loading
Loading