Snowflake OA Interview Coding Question: Maximum Number of Events You Can Attend

17 Views
No Comments

You are given an array of events where events[i] = [startDayi, endDayi]. Every event i starts at startDayi and ends at endDayi.

You can attend an event i on any day d where startDayi <= d <= endDayi. You can only attend one event at any time d.

Return the maximum number of events you can attend.

This is a classic greedy scheduling problem. Sort events by start day, then scan days in order while keeping all currently available events in a min-heap keyed by end day. Each day, attend the event that ends soonest to maximize future flexibility. The standard solution uses sorting plus a priority queue and runs in about O(n log n).

END
 0