Interval List Intersections
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given two lists of closed intervals, firstList and secondList. Within each list the intervals are sorted by start and pairwise disjoint (no two share even an endpoint). Interval [a, b] covers every real number x with a <= x <= b.
Return the intersection of the two lists: every maximal interval of points covered by both lists. A single shared point counts and is returned as [x, x].
Return the intervals sorted by start. If the lists never overlap, return []. Aim for O(n + m) time.
Examples
Constraints
- 0 <= firstList.length, secondList.length <= 1000
- 0 <= start_i <= end_i <= 10^9
- end_i < start_{i+1} within each list
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.