This challenge was greatly inspired by this Stack Overflow post.
Given a bunch of clients in terms of when they enter a room and when they exit it, determine the period(s) of time when the room has a maximum number of people. The time resolution should be to the minute.
For example, if there are three clients
8 - 10,
9 - 11,
10 - 12, then the correct answer would be
9 - 11; during this time period, there are two clients in the room, which is the largest possible.
Input will be a list of pairs in some form. That can be either a list of 2-tuples, an even-length list with elements interleaved, etc, any reasonable input format. The times can be given in any reasonable format, in either 12- or 24- hour time. You may also input time as the number of minutes past midnight.
Output should be a list of pairs in some form, but the output is stricter. The output cannot be a flat list, it must be a list of 2-tuples or a list of lists, etc. The times can be output in any reasonable format, in either 12- or 24- hour time. You may also output time as the number of minutes past midnight.
input output INPUT 08:00 - 10:00 09:00 - 11:00 10:00 - 12:00 OUTPUT 09:00 - 11:00 INPUT 08:20 - 09:20 09:00 - 09:10 08:00 - 09:30 08:50 - 10:40 OUTPUT 09:00 - 09:10 INPUT 08:00 - 10:00 09:00 - 10:00 09:30 - 11:00 OUTPUT 09:30 - 10:00 # The output is not always in the input list INPUT 00:00 - 02:00 01:00 - 03:00 04:00 - 06:00 05:00 - 07:00 OUTPUT # This is the expected output for when there are multiple time ranges with the same "business". 01:00 - 02:00 05:00 - 06:00
You may assume that the second time in a pair will always be after the first time. Time ranges will not run over midnight.