Problem · Array

Maximum Number of Events That Can Be Attended

Learn this problem
MediumSnowflake logoSnowflakeFULLTIMEPHONE SCREEN
See Snowflake hiring insights

Problem statement

You are given an array events, where events[i] = [startDay_i, endDay_i]. Event i can be attended on any one day from startDay_i through endDay_i, inclusive.

You may attend at most one event on any day. Return the maximum number of events you can attend.

Function

maxEvents(events: int[][]) → int

Examples

Example 1

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

Attend the three events on days 1, 2, and 3, respectively.

Example 2

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

Attend the two events ending on day 2 on days 1 and 2, then attend the remaining events on days 3 and 4.

Constraints

  • 1 <= events.length <= 10^5
  • events[i].length == 2
  • 1 <= startDay_i <= endDay_i <= 10^5

More Snowflake problems

drafts saved locally
public int maxEvents(int[][] events) {
    // Write your code here
}
events[[1,2],[2,3],[3,4]]
expected3
checking account