Interval problems (merge intervals)
Në shqip: Problemet me intervale
ShpjegimiSQ
Probleme me intervale kohore (takime, rezervime): rendit sipas fillimit, pastaj ec dhe bashko ato që mbivendosen. Shumë i zakonshëm në intervista.
EnglishEN
Problems with time intervals (meetings, bookings): sort by start, then walk through and merge the ones that overlap. Very common in interviews.
Si ta mendosh
Si të bashkosh oraret e takimeve në kalendar që të shohësh kur je i zënë.
Lexoje në anglisht
Like merging meeting times in a calendar to see when you're busy.
Shembull kodipython
def bashko(iv):
rez = []
for a, b in sorted(iv):
if rez and a <= rez[-1][1]: rez[-1][1] = max(rez[-1][1], b)
else: rez.append([a, b])