meeting_rooms

 1from itertools import pairwise
 2
 3
 4# @leet start
 5class Solution:
 6    def canAttendMeetings(self, intervals: list[list[int]]) -> bool:
 7        """
 8        This problem shows a schedule of meetings, unsorted, and asks if it's possible
 9        to make it to every meeting, granted no travel time (assume they're virtual meetings).
10        To do this, we sort all meetings and make sure that the start time of the next meeting
11        is always after the end time of the previous meeting.
12        """
13        return all(
14            prev_end <= curr_start
15            for (_, prev_end), (curr_start, _) in pairwise(sorted(intervals))
16        )
17
18
19# @leet end
20sol = Solution()
21
22
23def test():
24    assert not sol.canAttendMeetings([[0, 30], [5, 10], [15, 20]])
25    assert sol.canAttendMeetings([[7, 10], [2, 4]])
class Solution:
 6class Solution:
 7    def canAttendMeetings(self, intervals: list[list[int]]) -> bool:
 8        """
 9        This problem shows a schedule of meetings, unsorted, and asks if it's possible
10        to make it to every meeting, granted no travel time (assume they're virtual meetings).
11        To do this, we sort all meetings and make sure that the start time of the next meeting
12        is always after the end time of the previous meeting.
13        """
14        return all(
15            prev_end <= curr_start
16            for (_, prev_end), (curr_start, _) in pairwise(sorted(intervals))
17        )
def canAttendMeetings(self, intervals: list[list[int]]) -> bool:
 7    def canAttendMeetings(self, intervals: list[list[int]]) -> bool:
 8        """
 9        This problem shows a schedule of meetings, unsorted, and asks if it's possible
10        to make it to every meeting, granted no travel time (assume they're virtual meetings).
11        To do this, we sort all meetings and make sure that the start time of the next meeting
12        is always after the end time of the previous meeting.
13        """
14        return all(
15            prev_end <= curr_start
16            for (_, prev_end), (curr_start, _) in pairwise(sorted(intervals))
17        )

This problem shows a schedule of meetings, unsorted, and asks if it's possible to make it to every meeting, granted no travel time (assume they're virtual meetings). To do this, we sort all meetings and make sure that the start time of the next meeting is always after the end time of the previous meeting.

sol = <Solution object>
def test():
24def test():
25    assert not sol.canAttendMeetings([[0, 30], [5, 10], [15, 20]])
26    assert sol.canAttendMeetings([[7, 10], [2, 4]])