Skip to main content
Back to problems
Leetcode
Medium
Arrays
Heaps
Ordered Structures
Sorting
Uber
Maximum Number Of Events That Can Be Attended

Attend at most one event per day and maximize how many events you can complete before they expire.

Acceptance 100%
Problem Statement

You are given a list of events, where each event has a start day and an end day. An event can be attended on any one day within its inclusive date range. You can attend at most one event per day.

Your goal is to choose days and events so that the total number of attended events is maximized.

Find the maximum number of events you can attend.

Input Format

  • An array of events, where each event is represented as [startDay, endDay].
  • Each event may be attended on any single day d such that startDay <= d <= endDay.
  • At most one event can be attended on any day.

Output Format

  • Return a single integer: the maximum number of events that can be attended.

Constraints

  • 1 <= events.length
  • Each event has exactly two integers: startDay and endDay
  • A day can be used for at most one event
  • Each event can be attended at most once
Examples
Sample cases returned by the problem API.

Example 1

Input

events = [[1,2],[2,3],[3,4]]

Output

3

Explanation

Attend the first event on day 1, the second on day 2, and the third on day 3.

Example 2

Input

events = [[1,2],[2,3],[3,4],[1,2]]

Output

4

Explanation

One optimal schedule is: attend one [1,2] event on day 1, the other [1,2] event on day 2, [2,3] on day 3, and [3,4] on day 4.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.