TomoLink
CompaniesInfosysData Structures & AlgorithmsMaximum Number of Events That Can Be Attended
DSA
MediumArray

Maximum Number of Events That Can Be Attended

arraygreedysorting

Problem Statement

You are given an array of events where events[i] = [startDay _i , endDay _i ] . Every event i starts at startDay _i _ and ends at endDay _i .

You can attend an event i at any day d where startDay _i <= d <= endDay _i . You can only attend one event at any time d .

Return the maximum number of events you can attend .

Examples

Example 1
Input: events = [[1,2],[2,3],[3,4]]
Output: 3
You can attend all the three events. One way to attend them all is as shown. Attend the first event on day 1. Attend the second event on day 2. Attend the third event on day 3.
Example 2
Input: events= [[1,2],[2,3],[3,4],[1,2]]
Output: 4

Constraints

1 <= events.length <= 10 ^5
events[i].length == 2
1 <= startDay _i <= endDay _i <= 10 ^5
🤔
Medium
Difficulty
Topic Info
ModuleDSA
CategoryArray
Sub-topicGreedy
Tags
arraygreedysortingheap (priority queue)
Navigation
Maximum Number of Events That Can Be Attended [Medium] | Infosys Dsa | TomoLink