Data Structures & AlgorithmsModerateProduct Company SDE · Amazon/Microsoft-style OA

Problem: Remove the fewest meetings so that the rest do not overlap (meetings that only touch at an endpoint are fine).

Problem: Remove the fewest meetings so that the rest do not overlap (meetings that only touch at an endpoint are fine).
def remove_min(iv):
    iv.sort(key=lambda x: x[1])
    end, keep = float('-inf'), 0
    for s, e in iv:
        if s >= end:
            keep += 1; end = e
    return len(iv) - keep
print(remove_min([[1, 2], [2, 3], [3, 4], [1, 3]]), remove_min([[1, 10], [2, 3], [4, 5], [6, 7]]))
What is printed?
  1. A. 1 3
  2. B. 2 1
  3. C. 1 1
  4. D. 0 1

Correct answer: C. 1 1

Activity selection: sorting by END time and keeping each meeting that starts after the last kept end maximises the kept set. Second case: [2,3], [4,5], [6,7] are kept and only the long [1,10] goes. Sorting by start time would keep [1,10] first and remove 3. O(n log n).

More Coding Interview Problems questions

Exams that ask this topic