Data Structures & AlgorithmsHardProduct Company SDE · CP practice
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 [15,19], [19,24], [25,32], [17,20], [7,15], [30,32], what is the result?
- A. [7,15], [15,24], [25,32]
- B. [25,32], [7,24]
- C. [7,24], [25,32]
- D. [7,15], [15,19], [17,20], [19,24], [25,32], [30,32]
Correct answer: C. [7,24], [25,32]
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 [7,24], [25,32]. Requiring a strictly smaller start (< instead of ≤) would wrongly keep touching intervals separate, giving [7,15], [15,24], [25,32].
More Coding Interview Problems questions
- Using the merge-sort inversion-count technique (count, during each merge step, how many left-half elements are greater than the current…
- Problem: 7 servers are joined by cables one at a time. Count the connected groups at the end and how many cables were redundant (joined…
- 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…
- What is the length of the longest common subsequence of "ECAAEEDAE" and "BEEDEDD"?
- Using the merge-sort inversion-count technique (count, during each merge step, how many left-half elements are greater than the current…
- Fractional knapsack, capacity 16 (items can be split). Items (weight, value): (3, 8), (7, 6), (3, 8), (6, 8). Using the greedy…