|
| 1 | +{ |
| 2 | + "question_name": "insert_interval", |
| 3 | + "class_name": "InsertInterval", |
| 4 | + "method_name": "insert", |
| 5 | + "problem_number": "57", |
| 6 | + "problem_title": "Insert Interval", |
| 7 | + "difficulty": "Medium", |
| 8 | + "topics": "Array", |
| 9 | + "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.", |
| 11 | + "examples": [ |
| 12 | + { "input": "intervals = [[1,3],[6,9]], newInterval = [2,5]", "output": "[[1,5],[6,9]]" }, |
| 13 | + { |
| 14 | + "input": "intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]", |
| 15 | + "output": "[[1,2],[3,10],[12,16]]" |
| 16 | + } |
| 17 | + ], |
| 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]", |
| 20 | + "return_type": "list[list[int]]", |
| 21 | + "dummy_return": "[]", |
| 22 | + "imports": "", |
| 23 | + "test_cases": [ |
| 24 | + { |
| 25 | + "args": [ |
| 26 | + [ |
| 27 | + [1, 3], |
| 28 | + [6, 9] |
| 29 | + ], |
| 30 | + [2, 5] |
| 31 | + ], |
| 32 | + "expected": [ |
| 33 | + [1, 5], |
| 34 | + [6, 9] |
| 35 | + ] |
| 36 | + }, |
| 37 | + { |
| 38 | + "args": [ |
| 39 | + [ |
| 40 | + [1, 2], |
| 41 | + [3, 5], |
| 42 | + [6, 7], |
| 43 | + [8, 10], |
| 44 | + [12, 16] |
| 45 | + ], |
| 46 | + [4, 8] |
| 47 | + ], |
| 48 | + "expected": [ |
| 49 | + [1, 2], |
| 50 | + [3, 10], |
| 51 | + [12, 16] |
| 52 | + ] |
| 53 | + }, |
| 54 | + { "args": [[], [5, 7]], "expected": [[5, 7]] }, |
| 55 | + { "args": [[[1, 5]], [2, 3]], "expected": [[1, 5]] } |
| 56 | + ], |
| 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", |
| 61 | + "expected_param": "expected", |
| 62 | + "method_args": "intervals, newInterval", |
| 63 | + "test_setup": "", |
| 64 | + "test_logging": "", |
| 65 | + "assertion_code": "assert result == expected", |
| 66 | + "test_input_setup": "# Example test case\\nintervals = [[1,3],[6,9]]\\nnewInterval = [2,5]", |
| 67 | + "expected_output_setup": "expected = [[1,5],[6,9]]" |
| 68 | +} |
0 commit comments