Given an existing Python codebase with failing test cases, find the bug(s) and fix the code so the tests pass.
Asked in the Karat debugging round stage. The starter function is merge_intervals(intervals). It must return a new list of merged, non-overlapping intervals sorted by start value. Intervals that overlap or touch must be merged.
Signature: def merge_intervals(intervals):
Examples:
[[1, 3], [2, 6], [8, 10]] returns [[1, 6], [8, 10]] because the first two intervals overlap.[[5, 7], [1, 3], [3, 5]] returns [[1, 7]] because touching intervals are merged.Constraints: Each interval has two integers with start <= end; input length is at most 1,000; the input list must not be modified.
def merge_intervals(intervals):