521. Maximum Number of Events That Can Be Attended

MediumBinary SearchGreedyHeapSorting

Given events as [startDay, endDay] pairs, you can attend one event per day, on any day between its start and end inclusive. Return the maximum number of events you can attend. The input is a JSON array of [startDay, endDay] pairs.

Input: A JSON array of [startDay, endDay] pairs.

Output: Integer — the maximum events attended.

Examples

Example 1
Input: [[1,2],[2,3],[3,4],[1,2]]
Output: 4
Explanation: Attend all four on distinct days.
Example 2
Input: [[1,2],[2,3],[3,4]]
Output: 3
Explanation: One per day.
Example 3
Input: [[1,1]]
Output: 1
Explanation: Single event.

Constraints

Asked by

OracleMicrosoftAmazonGoogleBloombergMeta
Solve this problem in the editor →