Unexplained Sightings Outside Flight Intervals
Problem statement
You have flight records and times when objects were observed in the sky. Each flight is [departure, duration]: departure is an integer HHMM clock time, and duration is a number of minutes.
A flight covers the half-open interval from departure through, but excluding, landing. For example, [1655,10] covers 16:55 through 17:05, excluding 17:05. No flight lands after midnight.
An observation is unexplained when its time is outside every flight interval. The input guarantees at least one unexplained observation.
- For this exercise, assume the result contains every unexplained observation in the same order as
observations, retaining repeated occurrences. - For this exercise, assume unsorted, overlapping, touching, and repeated flight records are valid; any covering flight explains an observation.
- For this exercise, assume all clock values are valid same-day times, durations are positive, and a flight may land exactly at midnight.
Return the unexplained observation values in the original integer HHMM format. For example, 09:00 is represented as 900.
Function
unexplainedSightings(flights: int[][], observations: int[]) → int[]Examples
Example 1
flights = [[900,10],[1030,40],[1655,10]]observations = [900,910,1109,1110,1654,1655,1705]return = [910,1110,1654,1705]The flight records match the reported example; observation values are authored. A departure is covered, while its landing is excluded unless another flight covers it.
Example 2
flights = [[1000,20],[950,20],[1015,10]]observations = [1025,1005,949,950,1024]return = [1025,949]Overlapping flights jointly cover 09:50 through 10:25, excluding 10:25. Input observation order is retained.
Example 3
flights = []observations = [2359,0,2359]return = [2359,0,2359]Without flights every observation is unexplained, including both occurrences of 23:59.
Constraints
- For this exercise, assume
0 <= flights.length <= 500and1 <= observations.length <= 1000. - Each flight contains exactly two integers: its departure HHMM and duration in minutes.
- Clock hours are in
[0,23]and minute fields in[0,59]. 1 <= duration <= 1440, and departure in elapsed minutes plus duration is at most1440.- At least one observation is outside all flight intervals.