Data Structures & AlgorithmsHardProduct Company SDE · Amazon OA
Problem: The intervals [1,3], [2,4], [3,6], [7,8], [5,9], [8,10] are given. What is the minimum number of intervals to remove so that the remaining ones are pairwise non-overlapping (touching at an endpoint is allowed)?
- A. 3
- B. 1
- C. 2
- D. 4
Correct answer: C. 2
Keep the maximum set of non-overlapping intervals by greedily choosing the earliest-ending interval; the removal count is the total minus that maximum. Removing the longest intervals first is not optimal.
More Coding Interview Problems questions
- Problem: Find the number of unique triplets (as value sets) that sum to zero in [−1, 0, 1, 2, −1, −4].
- Problem: How many substrings of "eceba" contain exactly 2 distinct characters?
- Problem: For the array [3, 1, 4, 1, 5, 9, 2] and window size 3, compute the sum of the minimum of every contiguous window.
- Problem: The Euclidean algorithm is run on (1071, 462). How many division steps (a mod b operations) are performed until the remainder…
- Problem: Count the subarrays of [4, 2, 2, 4, 2] whose maximum equals the minimum (single elements count).
- Problem: Water is poured into the cells of a 1-dimensional array of heights [0,1,0,2,1,0,1,3,2,1,2,1]; each cell holds water up to…