Skip to content

Commit 00c39ff

Browse files
committed
feat: add more questions
1 parent c321ad1 commit 00c39ff

File tree

13 files changed

+315
-4
lines changed

13 files changed

+315
-4
lines changed

.templates/leetcode/json/minimum_window_substring.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"problem_title": "Minimum Window Substring",
66
"difficulty": "Hard",
77
"topics": "Hash Table, String, Sliding Window",
8-
"tags": ["grind-75", "neetcode-150"],
8+
"tags": ["grind-75"],
99
"readme_description": "Given two strings `s` and `t` of lengths `m` and `n` respectively, return the **minimum window substring** of `s` such that every character in `t` (including duplicates) is included in the window. If there is no such substring, return the empty string `\"\"`.\n\nThe testcases will be generated such that the answer is unique.",
1010
"readme_examples": [
1111
{
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"problem_name": "search_in_rotated_sorted_array",
3+
"solution_class_name": "Solution",
4+
"problem_number": "33",
5+
"problem_title": "Search in Rotated Sorted Array",
6+
"difficulty": "Medium",
7+
"topics": "Array, Binary Search",
8+
"tags": ["grind-75"],
9+
"readme_description": "There is an integer array `nums` sorted in ascending order (with **distinct** values).\n\nPrior to being passed to your function, `nums` is **possibly left rotated** at an unknown index `k` (`1 <= k < nums.length`) such that the resulting array is `[nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]` (**0-indexed**). For example, `[0,1,2,4,5,6,7]` might be left rotated by 3 indices and become `[4,5,6,7,0,1,2]`.\n\nGiven the array `nums` **after** the possible rotation and an integer `target`, return *the index of* `target` *if it is in* `nums`*, or* `-1` *if it is not in* `nums`.\n\nYou must write an algorithm with `O(log n)` runtime complexity.",
10+
"readme_examples": [
11+
{ "content": "```\nInput: nums = [4,5,6,7,0,1,2], target = 0\nOutput: 4\n```" },
12+
{ "content": "```\nInput: nums = [4,5,6,7,0,1,2], target = 3\nOutput: -1\n```" },
13+
{ "content": "```\nInput: nums = [1], target = 0\nOutput: -1\n```" }
14+
],
15+
"readme_constraints": "- `1 <= nums.length <= 5000`\n- `-10^4 <= nums[i] <= 10^4`\n- All values of `nums` are **unique**.\n- `nums` is an ascending array that is possibly rotated.\n- `-10^4 <= target <= 10^4`",
16+
"readme_additional": "",
17+
"solution_imports": "",
18+
"solution_methods": [
19+
{
20+
"name": "search",
21+
"parameters": "nums: list[int], target: int",
22+
"return_type": "int",
23+
"dummy_return": "-1"
24+
}
25+
],
26+
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution",
27+
"test_class_name": "SearchInRotatedSortedArray",
28+
"test_helper_methods": [
29+
{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }
30+
],
31+
"test_methods": [
32+
{
33+
"name": "test_search",
34+
"parametrize": "nums, target, expected",
35+
"parametrize_typed": "nums: list[int], target: int, expected: int",
36+
"test_cases": "[([4, 5, 6, 7, 0, 1, 2], 0, 4), ([4, 5, 6, 7, 0, 1, 2], 3, -1), ([1], 0, -1), ([1], 1, 0), ([3, 1], 1, 1)]",
37+
"body": "result = self.solution.search(nums, target)\nassert result == expected"
38+
}
39+
],
40+
"playground_imports": "from solution import Solution",
41+
"playground_test_case": "# Example test case\nnums = [4, 5, 6, 7, 0, 1, 2]\ntarget = 0\nexpected = 4",
42+
"playground_execution": "result = Solution().search(nums, target)\nresult",
43+
"playground_assertion": "assert result == expected"
44+
}

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 ?= minimum_window_substring
2+
PROBLEM ?= search_in_rotated_sorted_array
33
FORCE ?= 0
44

55
sync_submodules:

leetcode/container_with_most_water/tests.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,29 @@ def setup_method(self):
1010
self.solution = Solution()
1111

1212
@pytest.mark.parametrize(
13-
"height, expected", [([1, 8, 6, 2, 5, 4, 8, 3, 7], 49), ([1, 1], 1), ([1, 2, 1], 2)]
13+
"height, expected",
14+
[
15+
# Original cases
16+
([1, 8, 6, 2, 5, 4, 8, 3, 7], 49),
17+
([1, 1], 1),
18+
([1, 2, 1], 2),
19+
# Edge cases
20+
([2, 1], 1),
21+
([1, 2], 1),
22+
([0, 2], 0),
23+
([2, 0], 0),
24+
# Increasing heights
25+
([1, 2, 3, 4, 5], 6),
26+
# Decreasing heights
27+
([5, 4, 3, 2, 1], 6),
28+
# Same heights
29+
([3, 3, 3, 3], 9),
30+
# Large differences
31+
([1, 1000, 1], 2),
32+
([1000, 1, 1000], 2000),
33+
# Multiple peaks
34+
([2, 3, 4, 5, 18, 17, 6], 17),
35+
],
1436
)
1537
@logged_test
1638
def test_max_area(self, height: list[int], expected: int):

leetcode/evaluate_reverse_polish_notation/tests.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,24 @@ def setup_method(self):
1212
@pytest.mark.parametrize(
1313
"tokens, expected",
1414
[
15+
# Original cases
1516
(["2", "1", "+", "3", "*"], 9),
1617
(["4", "13", "5", "/", "+"], 6),
1718
(["10", "6", "9", "3", "+", "-11", "*", "/", "*", "17", "+", "5", "+"], 22),
19+
# Single number
20+
(["42"], 42),
21+
# Negative numbers
22+
(["-1"], -1),
23+
(["1", "-1", "+"], 0),
24+
# Basic operations
25+
(["3", "4", "+"], 7),
26+
(["5", "2", "-"], 3),
27+
(["6", "3", "*"], 18),
28+
(["8", "2", "/"], 4),
29+
# Division with negatives
30+
(["-3", "4", "+", "2", "*", "1", "-"], 1),
31+
# Complex expression
32+
(["15", "7", "1", "1", "+", "/", "/", "3", "*", "2", "1", "1", "+", "+", "-"], 11),
1833
],
1934
)
2035
@logged_test

leetcode/insert_interval/tests.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,25 @@ def setup_method(self):
1212
@pytest.mark.parametrize(
1313
"intervals, new_interval, expected",
1414
[
15+
# Original cases
1516
([[1, 3], [6, 9]], [2, 5], [[1, 5], [6, 9]]),
1617
([[1, 2], [3, 5], [6, 7], [8, 10], [12, 16]], [4, 8], [[1, 2], [3, 10], [12, 16]]),
18+
# Empty intervals
19+
([], [5, 7], [[5, 7]]),
20+
# Insert at beginning
21+
([[3, 5], [6, 9]], [1, 2], [[1, 2], [3, 5], [6, 9]]),
22+
# Insert at end
23+
([[1, 3], [6, 9]], [10, 12], [[1, 3], [6, 9], [10, 12]]),
24+
# No overlap
25+
([[1, 2], [4, 5]], [3, 3], [[1, 2], [3, 3], [4, 5]]),
26+
# Complete overlap
27+
([[1, 5]], [2, 3], [[1, 5]]),
28+
# Merge all intervals
29+
([[1, 2], [3, 4], [5, 6]], [0, 7], [[0, 7]]),
30+
# Adjacent intervals
31+
([[1, 3], [6, 9]], [4, 5], [[1, 3], [4, 5], [6, 9]]),
32+
# Touch boundaries
33+
([[1, 3], [6, 9]], [3, 6], [[1, 9]]),
1734
],
1835
)
1936
@logged_test

leetcode/minimum_window_substring/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
**Difficulty:** Hard
44
**Topics:** Hash Table, String, Sliding Window
5-
**Tags:** grind-75, neetcode-150
5+
**Tags:** grind-75
66

77
**LeetCode:** [Problem 76](https://leetcode.com/problems/minimum-window-substring/description/)
88

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Search in Rotated Sorted Array
2+
3+
**Difficulty:** Medium
4+
**Topics:** Array, Binary Search
5+
**Tags:** grind-75
6+
7+
**LeetCode:** [Problem 33](https://leetcode.com/problems/search-in-rotated-sorted-array/description/)
8+
9+
## Problem Description
10+
11+
There is an integer array `nums` sorted in ascending order (with **distinct** values).
12+
13+
Prior to being passed to your function, `nums` is **possibly left rotated** at an unknown index `k` (`1 <= k < nums.length`) such that the resulting array is `[nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]` (**0-indexed**). For example, `[0,1,2,4,5,6,7]` might be left rotated by 3 indices and become `[4,5,6,7,0,1,2]`.
14+
15+
Given the array `nums` **after** the possible rotation and an integer `target`, return _the index of_ `target` _if it is in_ `nums`_, or_ `-1` _if it is not in_ `nums`.
16+
17+
You must write an algorithm with `O(log n)` runtime complexity.
18+
19+
## Examples
20+
21+
### Example 1:
22+
23+
```
24+
Input: nums = [4,5,6,7,0,1,2], target = 0
25+
Output: 4
26+
```
27+
28+
### Example 2:
29+
30+
```
31+
Input: nums = [4,5,6,7,0,1,2], target = 3
32+
Output: -1
33+
```
34+
35+
### Example 3:
36+
37+
```
38+
Input: nums = [1], target = 0
39+
Output: -1
40+
```
41+
42+
## Constraints
43+
44+
- `1 <= nums.length <= 5000`
45+
- `-10^4 <= nums[i] <= 10^4`
46+
- All values of `nums` are **unique**.
47+
- `nums` is an ascending array that is possibly rotated.
48+
- `-10^4 <= target <= 10^4`

leetcode/search_in_rotated_sorted_array/__init__.py

Whitespace-only changes.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "imports",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"from solution import Solution"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 2,
16+
"id": "setup",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"# Example test case\n",
21+
"nums = [4, 5, 6, 7, 0, 1, 2]\n",
22+
"target = 0\n",
23+
"expected = 4"
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": 3,
29+
"id": "execute",
30+
"metadata": {},
31+
"outputs": [
32+
{
33+
"data": {
34+
"text/plain": [
35+
"4"
36+
]
37+
},
38+
"execution_count": 3,
39+
"metadata": {},
40+
"output_type": "execute_result"
41+
}
42+
],
43+
"source": [
44+
"result = Solution().search(nums, target)\n",
45+
"result"
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": 4,
51+
"id": "test",
52+
"metadata": {},
53+
"outputs": [],
54+
"source": [
55+
"assert result == expected"
56+
]
57+
}
58+
],
59+
"metadata": {
60+
"kernelspec": {
61+
"display_name": "leetcode-py-py3.13",
62+
"language": "python",
63+
"name": "python3"
64+
},
65+
"language_info": {
66+
"codemirror_mode": {
67+
"name": "ipython",
68+
"version": 3
69+
},
70+
"file_extension": ".py",
71+
"mimetype": "text/x-python",
72+
"name": "python",
73+
"nbconvert_exporter": "python",
74+
"pygments_lexer": "ipython3",
75+
"version": "3.13.7"
76+
}
77+
},
78+
"nbformat": 4,
79+
"nbformat_minor": 5
80+
}

0 commit comments

Comments
 (0)