Data Structures & AlgorithmsModerateProduct company OA · Amazon/Microsoft-style OA
Busy intervals [2,5), [4,7), [9,12), [11,13), [15,16) lie inside the working day [0, 20). How many time units in the day are free, i.e. not covered by any busy interval?
- A. 8
- B. 10
- C. 13
- D. 6
Correct answer: B. 10
Sort the busy intervals, merge the overlapping ones, and subtract the merged total from the day length. Adding the raw lengths double-counts the overlap between [2,5) and [4,7) and gives the trap.
More Coding Interview Problems questions
- Closed intervals [1,4], [2,6], [5,8], [7,9], [8,12], [10,11] must each contain at least one chosen integer point. What is the minimum…
- Jobs are triples (start, end, weight): (1,3,2), (2,5,4), (4,6,3), (6,8,5), (5,9,6). Jobs may be chosen together only when one ends no…
- Array a = [2, 1, 3, 4, 1, 2, 5, 1]. How many non-empty contiguous subarrays contain exactly as many odd numbers as even numbers?
- Array a = [4, -1, 2, -3, 5, -2, 1, 1, -4]. How many DISTINCT values appear among the sums of all non-empty contiguous subarrays?
- Array a = [6, 1, 8, 3, 9, 4, 2, 7, 5] has distinct values. How many ordered pairs (i, j) with i != j satisfy a[i] - a[j] = 4?
- For a = [1, 2, 3, 4, 5, 6, 7, 8], how many contiguous subarrays have a sum that is a multiple of 5?