Loading problem…
You're building a calendar scheduling feature for a meeting room booking app. Users can book time slots, and you need to merge overlapping time slots to show consolidated availability and prevent double-booking.
Given an array of intervals where intervals[i] = [start_i, end_i], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.
merge([[1,3],[2,6],[8,10],[15,18]]); // [[1,6],[8,10],[15,18]]
// Explanation: Intervals [1,3] and [2,6] overlap (2 ≤ 3), so they merge into [1,6].
// Intervals [8,10] and [15,18] don't overlap with any others, so they remain separate.merge([[1,4],[4,5]]); // [[1,5]]
// Explanation: Intervals [1,4] and [4,5] are considered overlapping because the end
// of the first (4) equals the start of the second (4). Since intervals are inclusive
// on both ends, they merge into [1,5].merge([[1,4],[2,3]]); // [[1,4]]
// Explanation: Interval [2,3] is completely contained within [1,4]. When one interval
// is fully inside another, we merge by keeping the larger interval, resulting in [1,4].This problem models real calendar and scheduling systems: