Skip to content

Maximum Number of Events That Can Be Attended

MediumIntervals
Decode it first. Clues, constraints, pattern and plan before any code.

events[i] = [start, end] means event i can be attended on any single day d with start <= d <= end. You can attend only one event per day, and attending an event takes just that one day. Return the maximum number of events you can attend.

[[1, 2], [2, 3], [3, 4]]          →  3   (day 1, day 2, day 3)
[[1, 2], [2, 3], [3, 4], [1, 2]]  →  4
[[1, 1], [1, 1], [1, 1]]          →  1

Constraints

  • 1 <= events.length <= 10^5
  • 1 <= start <= end <= 10^5