Data Structures & AlgorithmsVery hardIBM · Deloitte pattern
Merging overlapping intervals (sort by start, merge when the next interval's start is ≤ the current merged interval's end — touching endpoints count as overlapping) on [4,11], [11,19], [1,6], [2,10], [15,20], [26,33], [28,36], what is the result?
- A. [1,11], [11,20], [26,36]
- B. [1,6], [2,10], [4,11], [11,19], [15,20], [26,33], [28,36]
- C. [26,36], [1,20]
- D. [1,20], [26,36]
Correct answer: D. [1,20], [26,36]
After sorting by start time, two intervals merge whenever the next one's start is ≤ the current merged end (so [2,5] and [5,8] do merge, since they touch at 5); applying this gives [1,20], [26,36]. Requiring a strictly smaller start (< instead of ≤) would wrongly keep touching intervals separate, giving [1,11], [11,20], [26,36].
More Coding Interview Problems questions
- What is the length of the longest common subsequence of "EEAEEBB" and "DECDADAC"?
- Using the merge-sort inversion-count technique (count, during each merge step, how many left-half elements are greater than the current…
- Using a min-heap of size k (push each element, pop when size exceeds k, so the heap always holds the k largest seen so far), what is the k…
- Using the merge-sort inversion-count technique (count, during each merge step, how many left-half elements are greater than the current…
- Using a min-heap of size k (push each element, pop when size exceeds k, so the heap always holds the k largest seen so far), what is the k…
- Using the merge-sort inversion-count technique (count, during each merge step, how many left-half elements are greater than the current…