Merge Overlapping Date Ranges Given as Arrow-Separated Strings
Company: Nextdoor
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: A coding question asking to merge date ranges written as text with an arrow between the start and end dates, combining ranges that share at least one day and returning them in chronological order in the same format. It tests exact string parsing and formatting as well as interval merging.
Constraints
- 1 <= len(ranges) <= 10^4
- Every input string follows the format "YYYY-MM-DD -> YYYY-MM-DD" exactly, with one space on each side of `->`.
- Every date is a valid Gregorian calendar date from 1900-01-01 to 2100-12-31, and each range's start date is on or before its end date.
- The input may be in any order and may contain duplicate ranges.
Examples
Input: (['2024-01-01 -> 2024-01-10', '2024-01-05 -> 2024-01-15', '2024-02-01 -> 2024-02-03'],)
Expected Output: ['2024-01-01 -> 2024-01-15', '2024-02-01 -> 2024-02-03']
Explanation: Source example 1: the January ranges share Jan 5-10 and merge; the February range stays separate.
Input: (['2023-12-30 -> 2024-01-02', '2023-12-01 -> 2023-12-30', '2024-01-03 -> 2024-01-03'],)
Expected Output: ['2023-12-01 -> 2024-01-02', '2024-01-03 -> 2024-01-03']
Explanation: Source example 2: ranges sharing 2023-12-30 merge across the year end; the single day 2024-01-03 only touches and stays separate.
Hints
- A range includes both endpoints, so two ranges that share even a single day overlap, while two that only touch do not.
- Because every date is zero-padded YYYY-MM-DD, comparing two dates as text gives the same order as comparing them on the calendar.
- Ranges can end up in one merged group through a chain of overlaps, even when the first and last ranges in the chain share no day.