Union of K Sorted Interval Streams
Updated
Problem statement
Given k streams of closed integer intervals, return their union as sorted, pairwise-disjoint intervals.
- Each stream is sorted by start value.
- A stream may contain internal overlap.
- Merge the next interval when its start is at most the current merged end.
- Process the streams as a k-way merge: only one current interval from each stream needs to be active at a time.
Function
unionIntervalStreams(streams: int[][][]) → int[][]Examples
Example 1
streams = [[[1,3],[5,7]],[[2,4],[7,9]]]return = [[1,4],[5,9]]The first two intervals merge into [1,4]. The intervals [5,7] and [7,9] meet at 7 and merge into [5,9].
Example 2
streams = [[],[[-2,-1],[0,2]],[[2,3]]]return = [[-2,-1],[0,3]]The empty stream contributes nothing, and the two intervals meeting at 2 merge.
Constraints
streamscontains one or more interval streams.- Every interval is
[start, end]withstart <= end. - Each individual stream is sorted by nondecreasing start value.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Meeting Rooms IISalesforce · ONSITE INTERVIEWSalesforce interview questions
- Generate Complete Inputs for a Supplied ClassifierGeneral Motors · ONSITE INTERVIEW
- Minimum Meeting Rooms with AssignmentsUber · PHONE SCREEN · ONSITE INTERVIEWUber interview questions
- Meeting Rooms IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Minimum Workers with Job AssignmentsLyft · ONSITE INTERVIEWLyft interview questions
- Merge K Sorted Interval ListsBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Employee Free TimeIDFC Bank · ONSITE INTERVIEWIDFC Bank interview questions
- Meeting Rooms IIeBay · PHONE SCREENeBay interview questions
- Meeting Rooms IIByteDance · PHONE SCREENByteDance interview questions
- Minimum Meeting RoomsJP Morgan Chase · OAJP Morgan Chase interview questions