mirror of
https://github.com/harivansh-afk/veet-code.git
synced 2026-04-16 11:03:48 +00:00
clanker: test-veet (run)
This commit is contained in:
parent
c4d74aca3e
commit
684a9c5e3a
6 changed files with 253 additions and 0 deletions
35
problems/medium/merge-intervals/solution.py
Normal file
35
problems/medium/merge-intervals/solution.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
"""
|
||||
Merge Intervals
|
||||
|
||||
You're building a calendar app that needs to consolidate overlapping
|
||||
meetings. Given a list of time intervals represented as [start, end]
|
||||
pairs, merge all overlapping intervals and return the resulting list
|
||||
of non-overlapping intervals sorted by start time.
|
||||
|
||||
Two intervals overlap if one starts before the other ends.
|
||||
|
||||
Example 1:
|
||||
Input: intervals = [[1, 3], [2, 6], [8, 10], [15, 18]]
|
||||
Output: [[1, 6], [8, 10], [15, 18]]
|
||||
Explanation: [1, 3] and [2, 6] overlap, merged into [1, 6]
|
||||
|
||||
Example 2:
|
||||
Input: intervals = [[1, 4], [4, 5]]
|
||||
Output: [[1, 5]]
|
||||
Explanation: Intervals sharing an endpoint are considered overlapping
|
||||
|
||||
Example 3:
|
||||
Input: intervals = [[1, 4], [0, 4]]
|
||||
Output: [[0, 4]]
|
||||
Explanation: Input is not necessarily sorted
|
||||
|
||||
Constraints:
|
||||
- 0 <= len(intervals) <= 10^4
|
||||
- Each interval is [start, end] where start <= end
|
||||
- Start and end are non-negative integers
|
||||
"""
|
||||
|
||||
|
||||
def merge(intervals: list[list[int]]) -> list[list[int]]:
|
||||
"""Return a list of merged non-overlapping intervals sorted by start."""
|
||||
pass # Your implementation here
|
||||
47
problems/medium/merge-intervals/tests.py
Normal file
47
problems/medium/merge-intervals/tests.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
"""Tests for merge-intervals."""
|
||||
import pytest
|
||||
from solution import merge
|
||||
|
||||
|
||||
class TestBasicCases:
|
||||
"""Test basic functionality with typical inputs."""
|
||||
|
||||
def test_example_one(self):
|
||||
"""Test first example from problem description."""
|
||||
assert merge([[1, 3], [2, 6], [8, 10], [15, 18]]) == [[1, 6], [8, 10], [15, 18]]
|
||||
|
||||
def test_example_two(self):
|
||||
"""Test second example from problem description."""
|
||||
assert merge([[1, 4], [4, 5]]) == [[1, 5]]
|
||||
|
||||
def test_example_three(self):
|
||||
"""Test third example with unsorted input."""
|
||||
assert merge([[1, 4], [0, 4]]) == [[0, 4]]
|
||||
|
||||
def test_no_overlaps(self):
|
||||
"""Test intervals with no overlaps."""
|
||||
assert merge([[1, 2], [5, 6], [9, 10]]) == [[1, 2], [5, 6], [9, 10]]
|
||||
|
||||
|
||||
class TestEdgeCases:
|
||||
"""Test edge cases and boundary conditions."""
|
||||
|
||||
def test_empty_list(self):
|
||||
"""Test with no intervals."""
|
||||
assert merge([]) == []
|
||||
|
||||
def test_single_interval(self):
|
||||
"""Test with exactly one interval."""
|
||||
assert merge([[1, 5]]) == [[1, 5]]
|
||||
|
||||
def test_all_overlapping(self):
|
||||
"""Test when all intervals merge into one."""
|
||||
assert merge([[1, 4], [2, 5], [3, 6]]) == [[1, 6]]
|
||||
|
||||
def test_contained_interval(self):
|
||||
"""Test when one interval is fully inside another."""
|
||||
assert merge([[1, 10], [3, 5]]) == [[1, 10]]
|
||||
|
||||
def test_unsorted_input(self):
|
||||
"""Test with input not sorted by start time."""
|
||||
assert merge([[5, 6], [1, 3], [2, 4]]) == [[1, 4], [5, 6]]
|
||||
Loading…
Add table
Add a link
Reference in a new issue