Skip to content

Commit cd1fd1e

Browse files
committed
feat: dev
1 parent 15ce689 commit cd1fd1e

File tree

6 files changed

+32
-29
lines changed

6 files changed

+32
-29
lines changed

.amazonq/rules/problem-creation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- **Tree problems**: Use `.templates/leetcode/examples/tree.json5`
1515
- **Basic problems**: Use `.templates/leetcode/examples/basic.json5`
1616
- **Don't add extra fields** - templates are complete
17+
- **Python naming convention**: Use snake_case for all parameter names (e.g., `new_interval` not `newInterval`)
1718
- **If lint fails**: Fix JSON and regenerate, don't edit generated files
1819
- **After any manual edits**: Always update JSON template and verify with `make p-gen FORCE=1`
1920

.templates/leetcode/json/insert_interval.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
"difficulty": "Medium",
88
"topics": "Array",
99
"tags": ["grind-75"],
10-
"problem_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+
"problem_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 new_interval = [start, end] that represents the start and end of another interval.\n\nInsert new_interval 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.",
1111
"examples": [
12-
{ "input": "intervals = [[1,3],[6,9]], newInterval = [2,5]", "output": "[[1,5],[6,9]]" },
12+
{ "input": "intervals = [[1,3],[6,9]], new_interval = [2,5]", "output": "[[1,5],[6,9]]" },
1313
{
14-
"input": "intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]",
14+
"input": "intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], new_interval = [4,8]",
1515
"output": "[[1,2],[3,10],[12,16]]"
1616
}
1717
],
18-
"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",
19-
"parameters": "intervals: list[list[int]], newInterval: list[int]",
18+
"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- new_interval.length == 2\n- 0 <= start <= end <= 10^5",
19+
"parameters": "intervals: list[list[int]], new_interval: list[int]",
2020
"return_type": "list[list[int]]",
2121
"dummy_return": "[]",
2222
"imports": "",
@@ -54,15 +54,15 @@
5454
{ "args": [[], [5, 7]], "expected": [[5, 7]] },
5555
{ "args": [[[1, 5]], [2, 3]], "expected": [[1, 5]] }
5656
],
57-
"param_names": "intervals, newInterval, expected",
58-
"param_names_with_types": "intervals: list[list[int]], newInterval: list[int], expected: list[list[int]]",
59-
"input_description": "intervals={intervals}, newInterval={newInterval}",
60-
"input_params": "intervals, newInterval",
57+
"param_names": "intervals, new_interval, expected",
58+
"param_names_with_types": "intervals: list[list[int]], new_interval: list[int], expected: list[list[int]]",
59+
"input_description": "intervals={intervals}, new_interval={new_interval}",
60+
"input_params": "intervals, new_interval",
6161
"expected_param": "expected",
62-
"method_args": "intervals, newInterval",
62+
"method_args": "intervals, new_interval",
6363
"test_setup": "",
6464
"test_logging": "",
6565
"assertion_code": "assert result == expected",
66-
"test_input_setup": "# Example test case\nintervals = [[1,3],[6,9]]\nnewInterval = [2,5]",
66+
"test_input_setup": "# Example test case\nintervals = [[1,3],[6,9]]\nnew_interval = [2,5]",
6767
"expected_output_setup": "expected = [[1,5],[6,9]]"
6868
}

leetcode/insert_interval/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
## Problem Description
99

10-
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.
10+
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 new_interval = [start, end] that represents the start and end of another interval.
1111

12-
Insert 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).
12+
Insert new_interval 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).
1313

1414
Return intervals after the insertion.
1515

@@ -18,14 +18,14 @@ Return intervals after the insertion.
1818
### Example 1:
1919

2020
```
21-
Input: intervals = [[1,3],[6,9]], newInterval = [2,5]
21+
Input: intervals = [[1,3],[6,9]], new_interval = [2,5]
2222
Output: [[1,5],[6,9]]
2323
```
2424

2525
### Example 2:
2626

2727
```
28-
Input: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]
28+
Input: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], new_interval = [4,8]
2929
Output: [[1,2],[3,10],[12,16]]
3030
```
3131

@@ -35,5 +35,5 @@ Output: [[1,2],[3,10],[12,16]]
3535
- intervals[i].length == 2
3636
- 0 <= starti <= endi <= 10^5
3737
- intervals is sorted by starti in ascending order.
38-
- newInterval.length == 2
38+
- new_interval.length == 2
3939
- 0 <= start <= end <= 10^5

leetcode/insert_interval/playground.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"source": [
2020
"# Example test case\n",
2121
"intervals = [[1, 3], [6, 9]]\n",
22-
"newInterval = [2, 5]\n",
22+
"new_interval = [2, 5]\n",
2323
"expected = [[1, 5], [6, 9]]"
2424
]
2525
},
@@ -41,7 +41,7 @@
4141
}
4242
],
4343
"source": [
44-
"result = Solution().insert(intervals, newInterval)\n",
44+
"result = Solution().insert(intervals, new_interval)\n",
4545
"result"
4646
]
4747
},

leetcode/insert_interval/solution.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
class Solution:
22
# Time: O(n)
33
# Space: O(n)
4-
def insert(self, intervals: list[list[int]], newInterval: list[int]) -> list[list[int]]:
4+
def insert(self, intervals: list[list[int]], new_interval: list[int]) -> list[list[int]]:
55
result = []
66
i = 0
77

8-
# Add intervals before newInterval
9-
while i < len(intervals) and intervals[i][1] < newInterval[0]:
8+
# Add intervals before new_interval
9+
while i < len(intervals) and intervals[i][1] < new_interval[0]:
1010
result.append(intervals[i])
1111
i += 1
1212

1313
# Merge overlapping intervals
14-
while i < len(intervals) and intervals[i][0] <= newInterval[1]:
15-
newInterval[0] = min(newInterval[0], intervals[i][0])
16-
newInterval[1] = max(newInterval[1], intervals[i][1])
14+
while i < len(intervals) and intervals[i][0] <= new_interval[1]:
15+
new_interval[0] = min(new_interval[0], intervals[i][0])
16+
new_interval[1] = max(new_interval[1], intervals[i][1])
1717
i += 1
18-
result.append(newInterval)
18+
result.append(new_interval)
1919

2020
# Add remaining intervals
2121
result.extend(intervals[i:])

leetcode/insert_interval/tests.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def setup_method(self):
1111
self.solution = Solution()
1212

1313
@pytest.mark.parametrize(
14-
"intervals, newInterval, expected",
14+
"intervals, new_interval, expected",
1515
[
1616
([[1, 3], [6, 9]], [2, 5], [[1, 5], [6, 9]]),
1717
([[1, 2], [3, 5], [6, 7], [8, 10], [12, 16]], [4, 8], [[1, 2], [3, 10], [12, 16]]),
@@ -20,8 +20,10 @@ def setup_method(self):
2020
],
2121
)
2222
@logged_test
23-
def test_insert(self, intervals: list[list[int]], newInterval: list[int], expected: list[list[int]]):
24-
logger.info(f"Testing with intervals={intervals}, newInterval={newInterval}")
25-
result = self.solution.insert(intervals, newInterval)
23+
def test_insert(
24+
self, intervals: list[list[int]], new_interval: list[int], expected: list[list[int]]
25+
):
26+
logger.info(f"Testing with intervals={intervals}, new_interval={new_interval}")
27+
result = self.solution.insert(intervals, new_interval)
2628
logger.success(f"Got result: {result}")
2729
assert result == expected

0 commit comments

Comments
 (0)