Google Online Assessment Interview Question: Interval Name Overlap Table

21 Views
No Comments

You are given a table of people with three columns: Name, Start, and End. Each row represents an interval for a person.

Create a second table with columns Start, End, and Names. The output table should break the timeline into consecutive intervals using every unique start and end value from the input. For each interval, list all names whose original intervals cover that entire segment.

Example:

Name   | Start | End
Abby   | 10    | 100
Ben    | 50    | 70
Carla  | 60    | 120
David  | 150   | 300

Output:

Start | End | Names
10    | 50  | Abby
50    | 60  | Abby, Ben
60    | 70  | Abby, Ben, Carla
70    | 100 | Abby, Carla
100   | 120 | Carla
150   | 300 | David

This problem is about splitting the timeline into atomic intervals and finding which original ranges cover each segment. A practical solution is to collect all unique start and end points, sort them, and then examine each adjacent pair as one output interval. For each segment, include every name whose interval fully covers that range. The example shows how overlapping intervals produce merged name lists across consecutive segments.

END
 0