Skip to content
Decoder

Maximum Number of Events That Can Be Attended

Medium

Problem

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.

Example 1

Input
[[1, 2], [2, 3], [3, 4]]
Output
3
Why
day 1, day 2, day 3

Example 2

Input
[[1, 2], [2, 3], [3, 4], [1, 2]]
Output
4

Example 3

Input
[[1, 1], [1, 1], [1, 1]]
Output
1

Constraints

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.