Maximum Number of Events That Can Be Attended

You are given an array of events where events[i] = [startDayi, endDayi]. Every event i starts at startDayi and ends at endDayi.

You can attend an event i on any day d where startDayi <= d <= endDayi. You can only attend one event at any day d.

Return the maximum number of events you can attend.

Example 1
Inputevents = [[1,2],[2,3],[3,4]]
Output3
You can attend all three events by attending them on days 1, 2, and 3 respectively.
Example 2
Inputevents = [[1,2],[2,3],[3,4],[1,2]]
Output4
The four events can be scheduled on distinct valid days, so all four can be attended.

Constraints

  • 1 <= events.length <= 10^5
  • events[i].length == 2
  • 1 <= startDayi <= endDayi <= 10^5

Asked at 14 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate