Most Meetings You Can Attend When Each Takes One Day Within Its Range
SnowflakeSoftware Engineer · Technical ScreenLast updated
Each meeting can be attended on any single day within its range, and only one meeting fits on each day; return the largest number of meetings you can attend. It tests interval scheduling reasoning and an exchange argument for why a local choice stays optimal.
You are given a list of meetings, each of which can be attended on any one day within a range of days. Attending a meeting takes one whole day, and you can attend at most one meeting per day. Return the largest number of meetings you can attend.
Function Signature
def max_meetings_attended(meetings: list[list[int]]) -> int:
Rules
meetings[i] = [start, end]means meetingican be attended on any single daydwithstart <= d <= end; both ends are inclusive.- Each meeting counts at most once, and each day can be used for at most one meeting.
Constraints
1 <= len(meetings) <= 10^51 <= start <= end <= 10^5for every meeting
Examples
Example 1
Input: meetings = [[2, 3], [1, 2], [1, 2], [3, 4]]
Output: 4
The two meetings over days 1 to 2 take days 1 and 2, the meeting over days 2 to 3 takes day 3, and the meeting over days 3 to 4 takes day 4.
Example 2
Input: meetings = [[1, 1], [1, 1], [1, 2]]
Output: 2
Both meetings that are available only on day 1 need that day, so only one of them can be attended; the third takes day 2.
Example 3
Input: meetings = [[1, 2], [1, 2], [1, 2], [3, 3]]
Output: 3
Only two of the three meetings over days 1 to 2 fit, and the last meeting takes day 3.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.