Maximum Number of Events That Can Be Attended
Reported by candidates from Snowflake's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Snowflake reported this one in July 2026, and it looks like an interval problem but it isn't really about intervals. It reduces to a daily choice: on each day, which open event do you attend? Sort by start day, walk the days, and always pick the event that expires soonest. That's a greedy with a min-heap, and it's the whole question. If you've got an invite for the Snowflake OA this week, learn that loop cold. StealthCoder sits invisibly on your screen as a safety net if your mind goes blank mid-assessment, but the pattern below is short enough to memorize tonight.
The problem
You are given an array events, where events[i] = [startDay_i, endDay_i]. Event i can be attended on any one day from startDay_i through endDay_i, inclusive. You may attend at most one event on any day. Return the maximum number of events you can attend. Function maxEvents(events: int[][]) → int Examples Example 1 events = [[1,2],[2,3],[3,4]] return = 3 Attend the three events on days 1, 2, and 3, respectively. Example 2 events = [[1,2],[2,3],[3,4],[1,2]] return = 4 Attend the two events ending on day 2 on days 1 and 2, then attend the remaining events on days 3 and 4. Constraints 1 <= events.length <= 10^5 events[i].length == 2 1 <= startDay_i <= endDay_i <= 10^5
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: sort events by start day. Then simulate day by day. On each day, push the end days of every event starting that day into a min-heap. Pop any end day that's already before today, since those events expired. Then pop the smallest remaining end day and attend it, count one, move to the next day. Earliest deadline first is the greedy that works, because an event with a later deadline can wait. The common pitfall is sorting by end day alone and assigning the first free day, which gets messy and slow. Another is looping over every day up to 10^5 without skipping empty gaps. Jump the day forward when the heap is empty. Complexity is O(n log n). With 10^5 events, anything quadratic times out. If you blank on the heap cleanup during the live OA, StealthCoder is the hedge that hands you the loop.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Maximum Number of Events That Can Be Attended cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as maximum number of events that can be attended. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Snowflake's OA.
Snowflake reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Maximum Number of Events That Can Be Attended FAQ
What's the trick for the Snowflake max events problem?+
Earliest deadline first. Sort events by start day, and each day add all newly available end days to a min-heap. Discard expired ones, then attend the event with the smallest end day. That choice never hurts later days, which is why the greedy is correct.
How hard is this really?+
It's a LeetCode Medium-to-Hard level problem. The idea is short, but you have to see the greedy and pair it with a heap. Once you know that, the code is about fifteen lines. Most failures come from missing the expired-event cleanup step.
Why does sorting by end day alone fail?+
You'd need to assign each event the earliest free day within its range, which needs extra structure like a set or union-find to do fast. The heap by day approach is simpler and naturally handles which day each event takes.
What complexity should I aim for?+
O(n log n). With up to 10^5 events and days up to 10^5, a nested loop over events and days is too slow. Each event enters and leaves the heap once, so the heap work stays logarithmic per event.
How do I prepare for this in 48 hours?+
Write the heap loop from scratch twice without looking. Then test on [[1,2],[2,3],[3,4],[1,2]] and expect 4. Also test an input with a gap between events, to confirm you skip days correctly when the heap is empty.