Katkat

Solve two interval array problems

BlackRockData Engineer · Technical Screen

Last updated

This question evaluates proficiency with array and interval-manipulation concepts—specifically sorting, merging overlapping ranges, and robust edge-case handling in interval operations.

You are given two interval-based tasks from a technical screen for a data engineering role.

  1. Merge overlapping intervals
  • Input: an array of integer intervals intervals, where each interval is [start, end].
  • The intervals may be unsorted.
  • Return a new array where all overlapping intervals are merged.
  • Example: [[1,3],[2,6],[8,10],[15,18]] becomes [[1,6],[8,10],[15,18]].
  • In the interview, you only need to explain the algorithm clearly; full runnable code is not required.
  1. Insert and merge one interval
  • Input: a list of non-overlapping intervals sorted by start time, plus one additional interval new_interval.
  • Insert new_interval into the list so that the final result is still sorted and contains no overlapping intervals.
  • Example: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], new_interval = [4,8] should return [[1,2],[3,10],[12,16]].
  • For this task, write code or precise pseudocode that handles edge cases and passes test cases.

Discuss the key edge cases, such as empty input, intervals that fully contain one another, and insertion at the beginning or end.