Skip to content
BytePatterns

Most Events You Can Attend

MediumGreedy#greedy#min-heap#earliest-deadline~30m

Problem

A conference lists events as [startDay, endDay], inclusive. You can attend an event on any single day within its range, and you can attend at most one event per day. Return the largest number of events you can attend.

Examples

Input:  events = [[1, 2], [2, 3], [3, 4], [1, 2]]
Output: 4
Why:    days 1 and 2 go to the two [1, 2] events, then [2, 3] on day 3 and [3, 4] on day 4
Input:  events = [[1, 4], [4, 4], [2, 2], [3, 4], [1, 1]]
Output: 4
Input:  events = [[1, 1], [1, 1], [1, 1]]
Output: 1
Why:    edge case, three events compete for the same single day

Hints

0 / 3

Stuck on the idea rather than the code? Huffman Intuition covers it.