Back to course home
0% completed
Vote For New Content
My better solution :)
Mohammed Dh Abbas
May 24, 2024
from heapq import * class Solution: def findNextInterval(self, intervals): e_min_heap = [] s_min_heap = [] for i in range(len(intervals)): s_min_heap.append((intervals[i].start, i)) e_min_heap.append((intervals[i].end, i)) heapify(s_min_heap) heapify(e_min_heap) result = [-1 for _ in range(len(intervals))] while e_min_heap: end, end_index = heappop(e_min_heap) while s_min_heap: start, start_index = heappop(s_min_heap) if start_index > end_index and start >= end: result[end_index] = start_index break return result
0
0
Comments
Comments
T
tristan.nikitakis 5 months ago
this doesnt work for all test cases, below fails.
result = sol.findNextInterval([Interval(1, 3), Interval(2,5), Interval(5,10), Interval(3, 5), Interval(4, 6)])
On this page