Back to course home
0% completed
Vote For New Content
Python code is wrong. This is the updated code.
Sachin Dev S
Jul 28, 2024
import bisect from typing import List class Solution: def __init__(self): self.bookings = [] def book(self, nums: List[List[int]]) -> List[bool]: results = [] for interval in nums: start, end = interval event = (start, end) # Find the index where the event should be inserted to maintain sorted order idx = bisect.bisect_left(self.bookings, event) # Find lower and higher neighbors lower = self.bookings[idx - 1] if idx > 0 else None higher = self.bookings[idx] if idx < len(self.bookings) else None # Check for overlap with neighboring events if (lower is None or lower[1] <= start) and (higher is None or end <= higher[0]): bisect.insort(self.bookings, event) # Add to list if no overlap results.append(True) else: results.append(False) return results
1
0
Comments
Comments
On this page