Skip to contentKEEP THE CRAFTTHE SANCTUARY

Select the Most Non-Overlapping Intervals

Choose as many non-overlapping intervals as possible by always keeping the one that ends first.

The problem

Implement maximum_non_overlapping(intervals). Each interval is [start, end] with start < end. Two intervals overlap when they share more than a single point, so [1, 2] and [2, 3] do not overlap. Return the largest number of intervals you can choose so that no two chosen intervals overlap. intervals may be empty.

Starter code

def maximum_non_overlapping(intervals):
    pass

Public examples

  1. intervals = [[1, 4], [2, 3], [3, 5], [5, 7]]gives3
  2. intervals = [[0, 1], [1, 2], [2, 3]]gives3

Solving it in the practice book needs an active paid plan.

Open it in the practice book
One thought at a time.