1
# Runtime: 931 ms (Top 66.6%) | Memory: 45.16 MB (Top 22.2%)6
self, flowers: List[List[int]], people: List[int]8
# we ADD flowers in the order in which they start, but we remove them in the order they9
# end. For this reason, we sort the flowers by starting time but put them in a heap,10
# in which we remove them by ending time13
) # keep flowers untouched in case array should be constant14
blooming = [] # heap of active flowers15
answer = [-1] * len(people) # output array17
(people[i], i) for i in range(len(people))18
] # the people, ordered and indexed by their time21
i = 0 # going through starts22
for hour, person in hours:23
# add all flowers that have started24
while i < len(starts) and starts[i][0] <= hour:25
heappush(blooming, (starts[i][1], starts[i][0]))27
# now remove all flowers that have ended. Note that we only care about the absolute smallest,28
# and in python minheaps, that is always the first element - even if no other element's order31
blooming and blooming[0][0] < hour32
): # as long as the soonest to end blooming flower hasn't already stopped34
answer[person] = len(blooming)