Skip to content

Commit 740592b

Browse files
committed
feat: add maximum_profit_in_job_scheduling
1 parent 094e2bf commit 740592b

File tree

107 files changed

+3884
-2
lines changed

Some content is hidden

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

107 files changed

+3884
-2
lines changed

.templates/check_test_cases.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python3
2+
3+
import json
4+
from pathlib import Path
5+
6+
def count_test_cases(json_data):
7+
"""Count total test cases across all test methods."""
8+
total = 0
9+
10+
# Handle both direct test_methods and nested _test_methods.list
11+
test_methods = json_data.get("test_methods", [])
12+
if not test_methods and "_test_methods" in json_data:
13+
test_methods = json_data["_test_methods"].get("list", [])
14+
15+
for method in test_methods:
16+
test_cases = method.get("test_cases", "")
17+
if test_cases.strip():
18+
# Count tuples/lists in test_cases string
19+
total += max(test_cases.count("("), test_cases.count("["))
20+
return total
21+
22+
def main():
23+
json_dir = Path(".templates/leetcode/json")
24+
files_with_few_tests = []
25+
26+
for json_file in json_dir.glob("*.json"):
27+
try:
28+
with open(json_file) as f:
29+
data = json.load(f)
30+
31+
test_count = count_test_cases(data)
32+
if test_count <= 10:
33+
files_with_few_tests.append((json_file.name, test_count))
34+
except Exception as e:
35+
print(f"Error reading {json_file.name}: {e}")
36+
37+
# Sort by test count
38+
files_with_few_tests.sort(key=lambda x: x[1])
39+
40+
print(f"Files with ≤10 test cases ({len(files_with_few_tests)} total):")
41+
for filename, count in files_with_few_tests:
42+
print(f"{filename}: {count} test cases")
43+
44+
if __name__ == "__main__":
45+
main()
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"problem_name": "flood_fill",
3+
"solution_class_name": "Solution",
4+
"problem_number": "733",
5+
"problem_title": "Flood Fill",
6+
"difficulty": "Easy",
7+
"topics": "Array, Depth-First Search, Breadth-First Search, Matrix",
8+
"_tags": { "list": ["grind-75"] },
9+
"readme_description": "You are given an image represented by an `m x n` grid of integers `image`, where `image[i][j]` represents the pixel value of the image. You are also given three integers `sr`, `sc`, and `color`. Your task is to perform a **flood fill** on the image starting from the pixel `image[sr][sc]`.\n\nTo perform a **flood fill**:\n\n1. Begin with the starting pixel and change its color to `color`.\n2. Perform the same process for each pixel that is **directly adjacent** (pixels that share a side with the original pixel, either horizontally or vertically) and shares the **same color** as the starting pixel.\n3. Keep **repeating** this process by checking neighboring pixels of the *updated* pixels and modifying their color if it matches the original color of the starting pixel.\n4. The process **stops** when there are **no more** adjacent pixels of the original color to update.\n\nReturn the **modified** image after performing the flood fill.",
10+
"_readme_examples": {
11+
"list": [
12+
{
13+
"content": "![Example 1](https://assets.leetcode.com/uploads/2021/06/01/flood1-grid.jpg)\n\n```\nInput: image = [[1,1,1],[1,1,0],[1,0,1]], sr = 1, sc = 1, color = 2\nOutput: [[2,2,2],[2,2,0],[2,0,1]]\n```\n**Explanation:** From the center of the image with position `(sr, sc) = (1, 1)` (i.e., the red pixel), all pixels connected by a path of the same color as the starting pixel (i.e., the blue pixels) are colored with the new color. Note the bottom corner is not colored 2, because it is not horizontally or vertically connected to the starting pixel."
14+
},
15+
{
16+
"content": "```\nInput: image = [[0,0,0],[0,0,0]], sr = 0, sc = 0, color = 0\nOutput: [[0,0,0],[0,0,0]]\n```\n**Explanation:** The starting pixel is already colored with 0, which is the same as the target color. Therefore, no changes are made to the image."
17+
}
18+
]
19+
},
20+
"readme_constraints": "- `m == image.length`\n- `n == image[i].length`\n- `1 <= m, n <= 50`\n- `0 <= image[i][j], color < 2^16`\n- `0 <= sr < m`\n- `0 <= sc < n`",
21+
"readme_additional": "",
22+
"helpers_imports": "",
23+
"helpers_content": "",
24+
"helpers_run_name": "flood_fill",
25+
"helpers_run_signature": "(solution_class: type, image: list[list[int]], sr: int, sc: int, color: int)",
26+
"helpers_run_body": " implementation = solution_class()\n return implementation.flood_fill(image, sr, sc, color)",
27+
"helpers_assert_name": "flood_fill",
28+
"helpers_assert_signature": "(result: list[list[int]], expected: list[list[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_flood_fill, run_flood_fill\nfrom .solution import Solution",
34+
"test_content": "",
35+
"test_class_name": "FloodFill",
36+
"test_class_content": " def setup_method(self):\n self.solution = Solution()",
37+
"_solution_methods": {
38+
"list": [
39+
{
40+
"name": "flood_fill",
41+
"signature": "(self, image: list[list[int]], sr: int, sc: int, color: int) -> list[list[int]]",
42+
"body": " # TODO: Implement flood_fill\n return []"
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_flood_fill",
53+
"signature": "(self, image: list[list[int]], sr: int, sc: int, color: int, expected: list[list[int]])",
54+
"parametrize": "image, sr, sc, color, expected",
55+
"test_cases": "[([[1, 1, 1], [1, 1, 0], [1, 0, 1]], 1, 1, 2, [[2, 2, 2], [2, 2, 0], [2, 0, 1]]), ([[0, 0, 0], [0, 0, 0]], 0, 0, 0, [[0, 0, 0], [0, 0, 0]]), ([[0, 0, 0], [0, 1, 1]], 1, 1, 1, [[0, 0, 0], [0, 1, 1]]), ([[1, 1, 1], [1, 1, 0], [1, 0, 1]], 1, 1, 1, [[1, 1, 1], [1, 1, 0], [1, 0, 1]])]",
56+
"body": " result = run_flood_fill(Solution, image, sr, sc, color)\n assert_flood_fill(result, expected)"
57+
}
58+
]
59+
},
60+
"playground_imports": "from helpers import run_flood_fill, assert_flood_fill\nfrom solution import Solution",
61+
"playground_setup": "# Example test case\nimage = [[1, 1, 1], [1, 1, 0], [1, 0, 1]]\nsr = 1\nsc = 1\ncolor = 2\nexpected = [[2, 2, 2], [2, 2, 0], [2, 0, 1]]",
62+
"playground_run": "result = run_flood_fill(Solution, image, sr, sc, color)\nresult",
63+
"playground_assert": "assert_flood_fill(result, expected)"
64+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"problem_name": "implement_queue_using_stacks",
3+
"solution_class_name": "MyQueue",
4+
"problem_number": "232",
5+
"problem_title": "Implement Queue using Stacks",
6+
"difficulty": "Easy",
7+
"topics": "Stack, Design, Queue",
8+
"_tags": { "list": ["grind-75"] },
9+
"readme_description": "Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (`push`, `peek`, `pop`, and `empty`).\n\nImplement the `MyQueue` class:\n\n- `void push(int x)` Pushes element x to the back of the queue.\n- `int pop()` Removes the element from the front of the queue and returns it.\n- `int peek()` Returns the element at the front of the queue.\n- `boolean empty()` Returns `true` if the queue is empty, `false` otherwise.",
10+
"_readme_examples": {
11+
"list": [
12+
{
13+
"content": "```\nInput\n[\"MyQueue\", \"push\", \"push\", \"peek\", \"pop\", \"empty\"]\n[[], [1], [2], [], [], []]\nOutput\n[null, null, null, 1, 1, false]\n```\n**Explanation:**\n```\nMyQueue myQueue = new MyQueue();\nmyQueue.push(1); // queue is: [1]\nmyQueue.push(2); // queue is: [1, 2] (leftmost is front of the queue)\nmyQueue.peek(); // return 1\nmyQueue.pop(); // return 1, queue is [2]\nmyQueue.empty(); // return false\n```"
14+
}
15+
]
16+
},
17+
"readme_constraints": "- 1 <= x <= 9\n- At most 100 calls will be made to push, pop, peek, and empty.\n- All the calls to pop and peek are valid.",
18+
"readme_additional": "**Notes:**\n- You must use **only** standard operations of a stack, which means only `push to top`, `peek/pop from top`, `size`, and `is empty` operations are valid.\n- Depending on your language, the stack may not be supported natively. You may simulate a stack using a list or deque (double-ended queue) as long as you use only a stack's standard operations.\n\n**Follow-up:** Can you implement the queue such that each operation is amortized `O(1)` time complexity? In other words, performing `n` operations will take overall `O(n)` time even if one of those operations may take longer.",
19+
"helpers_imports": "",
20+
"helpers_content": "",
21+
"helpers_run_name": "my_queue",
22+
"helpers_run_signature": "(solution_class: type, operations: list[str], inputs: list[list[int]])",
23+
"helpers_run_body": " queue = None\n results: list[int | None | bool] = []\n for i, op in enumerate(operations):\n if op == 'MyQueue':\n queue = solution_class()\n results.append(None)\n elif op == 'push' and queue is not None:\n queue.push(inputs[i][0])\n results.append(None)\n elif op == 'pop' and queue is not None:\n results.append(queue.pop())\n elif op == 'peek' and queue is not None:\n results.append(queue.peek())\n elif op == 'empty' and queue is not None:\n results.append(queue.empty())\n return results, queue",
24+
"helpers_assert_name": "my_queue",
25+
"helpers_assert_signature": "(result: list[int | None | bool], expected: list[int | None | 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_my_queue, run_my_queue\nfrom .solution import MyQueue",
31+
"test_content": "",
32+
"test_class_name": "ImplementQueueUsingStacks",
33+
"test_class_content": "",
34+
"_solution_methods": {
35+
"list": [
36+
{
37+
"name": "__init__",
38+
"signature": "(self) -> None",
39+
"body": " # TODO: Initialize\n pass"
40+
},
41+
{
42+
"name": "push",
43+
"signature": "(self, x: int) -> None",
44+
"body": " # TODO: Implement push\n pass"
45+
},
46+
{
47+
"name": "pop",
48+
"signature": "(self) -> int",
49+
"body": " # TODO: Implement pop\n return 0"
50+
},
51+
{
52+
"name": "peek",
53+
"signature": "(self) -> int",
54+
"body": " # TODO: Implement peek\n return 0"
55+
},
56+
{
57+
"name": "empty",
58+
"signature": "(self) -> bool",
59+
"body": " # TODO: Implement empty\n return True"
60+
}
61+
]
62+
},
63+
"_test_helper_methods": { "list": [] },
64+
"_test_methods": {
65+
"list": [
66+
{
67+
"name": "test_queue_operations",
68+
"signature": "(self, operations: list[str], inputs: list[list[int]], expected: list[int | None | bool])",
69+
"parametrize": "operations, inputs, expected",
70+
"test_cases": "[(['MyQueue', 'push', 'push', 'peek', 'pop', 'empty'], [[], [1], [2], [], [], []], [None, None, None, 1, 1, False]), (['MyQueue', 'empty', 'push', 'peek', 'pop', 'empty'], [[], [], [1], [], [], []], [None, True, None, 1, 1, True]), (['MyQueue', 'push', 'push', 'push', 'pop', 'pop', 'peek', 'pop', 'empty'], [[], [1], [2], [3], [], [], [], [], []], [None, None, None, None, 1, 2, 3, 3, True])]",
71+
"body": " result, _ = run_my_queue(MyQueue, operations, inputs)\n assert_my_queue(result, expected)"
72+
}
73+
]
74+
},
75+
"playground_imports": "from helpers import run_my_queue, assert_my_queue\nfrom solution import MyQueue",
76+
"playground_setup": "# Example test case\noperations = ['MyQueue', 'push', 'push', 'peek', 'pop', 'empty']\ninputs = [[], [1], [2], [], [], []]\nexpected = [None, None, None, 1, 1, False]",
77+
"playground_run": "result, queue = run_my_queue(MyQueue, operations, inputs)\nprint(result)\nqueue",
78+
"playground_assert": "assert_my_queue(result, expected)"
79+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"problem_name": "insert_interval",
3+
"solution_class_name": "Solution",
4+
"problem_number": "57",
5+
"problem_title": "Insert Interval",
6+
"difficulty": "Medium",
7+
"topics": "Array",
8+
"_tags": { "list": ["grind-75"] },
9+
"readme_description": "You are given an array of non-overlapping intervals `intervals` where `intervals[i] = [starti, endi]` represent the start and the end of the ith interval and `intervals` is sorted in ascending order by `starti`. You are also given an interval `newInterval = [start, end]` that represents the start and end of another interval.\n\nInsert `newInterval` into `intervals` such that `intervals` is still sorted in ascending order by `starti` and `intervals` still does not have any overlapping intervals (merge overlapping intervals if necessary).\n\nReturn `intervals` after the insertion.",
10+
"_readme_examples": {
11+
"list": [
12+
{
13+
"content": "```\nInput: intervals = [[1,3],[6,9]], newInterval = [2,5]\nOutput: [[1,5],[6,9]]\n```"
14+
},
15+
{
16+
"content": "```\nInput: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]\nOutput: [[1,2],[3,10],[12,16]]\nExplanation: Because the new interval [4,8] overlaps with [3,5],[6,7],[8,10].\n```"
17+
}
18+
]
19+
},
20+
"readme_constraints": "- 0 <= intervals.length <= 10^4\n- intervals[i].length == 2\n- 0 <= starti <= endi <= 10^5\n- intervals is sorted by starti in ascending order\n- newInterval.length == 2\n- 0 <= start <= end <= 10^5",
21+
"readme_additional": "",
22+
"helpers_imports": "",
23+
"helpers_content": "",
24+
"helpers_run_name": "insert",
25+
"helpers_run_signature": "(solution_class: type, intervals: list[list[int]], new_interval: list[int])",
26+
"helpers_run_body": " implementation = solution_class()\n return implementation.insert(intervals, new_interval)",
27+
"helpers_assert_name": "insert",
28+
"helpers_assert_signature": "(result: list[list[int]], expected: list[list[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_insert, run_insert\nfrom .solution import Solution",
34+
"test_content": "",
35+
"test_class_name": "InsertInterval",
36+
"test_class_content": " def setup_method(self):\n self.solution = Solution()",
37+
"_solution_methods": {
38+
"list": [
39+
{
40+
"name": "insert",
41+
"signature": "(self, intervals: list[list[int]], new_interval: list[int]) -> list[list[int]]",
42+
"body": " # TODO: Implement insert\n return []"
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_insert",
53+
"signature": "(self, intervals: list[list[int]], new_interval: list[int], expected: list[list[int]])",
54+
"parametrize": "intervals, new_interval, expected",
55+
"test_cases": "[([[1,3],[6,9]], [2,5], [[1,5],[6,9]]), ([[1,2],[3,5],[6,7],[8,10],[12,16]], [4,8], [[1,2],[3,10],[12,16]]), ([], [5,7], [[5,7]]), ([[1,5]], [2,3], [[1,5]]), ([[1,5]], [6,8], [[1,5],[6,8]]), ([[1,5]], [0,0], [[0,0],[1,5]]), ([[3,5],[12,15]], [6,6], [[3,5],[6,6],[12,15]])]",
56+
"body": " result = run_insert(Solution, intervals, new_interval)\n assert_insert(result, expected)"
57+
}
58+
]
59+
},
60+
"playground_imports": "from helpers import run_insert, assert_insert\nfrom solution import Solution",
61+
"playground_setup": "# Example test case\nintervals = [[1,3],[6,9]]\nnew_interval = [2,5]\nexpected = [[1,5],[6,9]]",
62+
"playground_run": "result = run_insert(Solution, intervals, new_interval)\nresult",
63+
"playground_assert": "assert_insert(result, expected)"
64+
}

0 commit comments

Comments
 (0)