Ctrl K

One Event per Day

Medium
A conference runs a set of events: events[i] = [start, end] means event i is on every day from start to end, inclusive. To count an event as visited, you only need to show up on any single day in that range. You can visit at most one event per day. Return the largest number of different events you can visit.
Example 1
events=[[2, 4], [2, 2], [3, 3], [1, 4]] → 4

Day 1 goes to [1, 4], day 2 to [2, 2], day 3 to [3, 3] and day 4 to [2, 4], so all four fit.

Example 2
events=[[5, 5], [5, 5], [5, 6]] → 2

Two events take place only on day 5, and the only other day, 6, goes to [5, 6]. One of the one-day events has to be skipped.

Example 3
events=[[7, 9]] → 1
Constraints
  • 1 ≤ len(events) ≤ 10⁵
  • events[i].length = 2
  • 1 ≤ start ≤ end ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsStudios for Recording Sessions MediumJobs With a Cooldown MediumSpread Out the Labels MediumCross Out Half the List MediumPrices That Fade With Each Sale Medium
loading Python…
Input
events=[[2, 4], [2, 2], [3, 3], [1, 4]]
Expected
4

Run checks the first 3 tests in your browser. Submit checks all 96 tests on the server, hidden ones included.