Created
September 6, 2020 05:24
-
-
Save abrarShariar/ca4f892f117329d86748e953f7ff21b6 to your computer and use it in GitHub Desktop.
merge meetings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def merge_ranges(meetings): | |
if len(meetings) == 0: | |
return meetings | |
meetings.sort(key=lambda x: x[0]) | |
merged_list = [(meetings[0])] | |
for current_start_time, current_end_time in meetings[1:]: | |
# check if the current start time is less than the end time of the latest end time in the merged list | |
last_merged_start, last_merged_end = merged_list[-1] | |
if current_start_time <= last_merged_end: | |
merged_list[-1] = (last_merged_start, max(current_end_time, last_merged_end)) | |
else: | |
merged_list.append((current_start_time, current_end_time)) | |
return merged_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment