The core merge logic wasn't the hard part, I've done LC 56 before.
First, normalize each interval into a linear numeric representation by converting day and time to minutes from Monday 00:00, splitting any wrapping intervals into two parts. Then sort all intervals by start time and merge overlapping or adjacent ones, finally converting back to the original format.
Pro tip: Clarify upfront whether intervals are inclusive or exclusive at endpoints, as this affects adjacency merging (e.g., 10:00-11:00 and 11:00-12:00 are adjacent if end is exclusive). Also, mention that you'd handle edge cases like full-week intervals and empty input.
Ask about interval inclusivity, time zone assumptions, and whether intervals can span multiple weeks. Confirm the expected output format and sorting order.
Convert each 'DAY HH:MM' to total minutes from Monday 00:00. For wrapping intervals (end < start), split into two: [start, end of week] and [start of week, end].
Sort all intervals by start time. Iterate and merge if the next interval's start is <= current end (or < if exclusive). Keep track of merged intervals.
After merging, check if the first and last intervals can merge across the week boundary (e.g., last ends Sunday 24:00 and first starts Monday 00:00). If so, combine them.
Convert merged intervals back to 'DAY HH:MM' format, ensuring chronological order. If an interval spans the entire week, represent it appropriately.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.