Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Weighted intervals (start, end, value): (0,5,4), (3,9,6), (6,10,3), (9,12,5). Choose two intervals that do not overlap (touching at an endpoint is allowed) to maximise total value. What is the maximum total value?
- A. 11
- B. 14
- C. 9
- D. 12
Correct answer: A. 11
Compare every pair of intervals: two intervals are compatible when one ends no later than the other starts. Among compatible pairs, the best total here is the answer; the pair with the single highest value may not be compatible with a second high-value interval.
More Coding Interview Problems questions
- Array a = [-2, 5, -1, 4, -3, 6]. How many contiguous subarrays have a sum strictly between 0 and 10?
- Sorted array [2, 3, 7, 9, 12, 15, 18]. How many index pairs i < j have a difference srt[j] - srt[i] in the range (3, 8], i.e. greater than…
- How many integers x with 1 <= x <= 30 have a binary representation with no two adjacent 1-bits?
- From the ten numbers [3, 8, 12, 5, 7, 10, 1, 4, 9, 6], how many 3-element subsets have a sum divisible by 5?
- A car starts at position 0 with 10 litres of fuel. It must reach position 40; it uses one litre per unit of distance. Gas stations at…
- From [5, 9, 2, 14, 7, 3, 8], keep as many values as possible so that the largest kept value is at most twice the smallest kept value. What…