At a trading firm like Jane Street, market activity is recorded as time intervals. Given a list of intervals representing active trading windows, merge all overlapping intervals and return the condensed list in ascending order.
Implement a function that takes intervals, a list of lists where each element is [start, end] and start <= end. Return a new list of merged intervals, where any overlapping or touching intervals are combined into a single interval.
Example 1
intervals = [[1,3],[2,6],[8,10],[15,18]][[1,6],[8,10],[15,18]][1,3] and [2,6] overlap, so they merge into [1,6].Example 2
intervals = [[1,4],[4,5]][[1,5]]4, so they are merged.1 <= len(intervals) <= 10^4intervals[i].length == 20 <= start <= end <= 10^6intervals = [[1,3],[2,6],[8,10],[15,18]]Output[[1,6],[8,10],[15,18]]WhyThe first two intervals overlap and merge into `[1,6]`. The others remain separate.intervals = [[1,4],[4,5]]Output[[1,5]]WhyBecause the second interval starts exactly when the first ends, they are treated as one continuous interval.1 <= len(intervals) <= 10^4intervals[i].length == 20 <= intervals[i][0] <= intervals[i][1] <= 10^6Intervals may be unsortedTouching intervals should also be mergeddef merge_trade_intervals(intervals):