|
| 1 | +{ |
| 2 | + "problem_name": "merge_intervals", |
| 3 | + "solution_class_name": "Solution", |
| 4 | + "problem_number": "56", |
| 5 | + "problem_title": "Merge Intervals", |
| 6 | + "difficulty": "Medium", |
| 7 | + "topics": "Array, Sorting", |
| 8 | + "tags": ["grind-75"], |
| 9 | + "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.", |
| 10 | + "readme_examples": [ |
| 11 | + { |
| 12 | + "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]." |
| 13 | + }, |
| 14 | + { |
| 15 | + "content": "```\nInput: intervals = [[1,4],[4,5]]\nOutput: [[1,5]]\n```\n**Explanation:** Intervals [1,4] and [4,5] are considered overlapping." |
| 16 | + }, |
| 17 | + { |
| 18 | + "content": "```\nInput: intervals = [[4,7],[1,4]]\nOutput: [[1,7]]\n```\n**Explanation:** Intervals [1,4] and [4,7] are considered overlapping." |
| 19 | + } |
| 20 | + ], |
| 21 | + "readme_constraints": "- `1 <= intervals.length <= 10^4`\n- `intervals[i].length == 2`\n- `0 <= starti <= endi <= 10^4`", |
| 22 | + "readme_additional": "", |
| 23 | + "solution_imports": "", |
| 24 | + "solution_methods": [ |
| 25 | + { |
| 26 | + "name": "merge", |
| 27 | + "parameters": "intervals: list[list[int]]", |
| 28 | + "return_type": "list[list[int]]", |
| 29 | + "dummy_return": "[]" |
| 30 | + } |
| 31 | + ], |
| 32 | + "test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution", |
| 33 | + "test_class_name": "MergeIntervals", |
| 34 | + "test_helper_methods": [ |
| 35 | + { "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" } |
| 36 | + ], |
| 37 | + "test_methods": [ |
| 38 | + { |
| 39 | + "name": "test_merge", |
| 40 | + "parametrize": "intervals, expected", |
| 41 | + "parametrize_typed": "intervals: list[list[int]], expected: list[list[int]]", |
| 42 | + "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]])]", |
| 43 | + "body": "result = self.solution.merge(intervals)\nassert result == expected" |
| 44 | + } |
| 45 | + ], |
| 46 | + "playground_imports": "from solution import Solution", |
| 47 | + "playground_test_case": "# Example test case\nintervals = [[1,3],[2,6],[8,10],[15,18]]\nexpected = [[1,6],[8,10],[15,18]]", |
| 48 | + "playground_execution": "result = Solution().merge(intervals)\nresult", |
| 49 | + "playground_assertion": "assert result == expected" |
| 50 | +} |
0 commit comments