Volunteer availability
MediumOnline Assessment
Find the times of the week when enough volunteers are available to run the community pantry.
Each element of availability describes one volunteer: day sections separated by ;, each "<Day> <range>,<range>,..." where <Day> is Mon, Tue, Wed, Thu, Fri, Sat or Sun and a range is "HH:MM-HH:MM" (24-hour; 24:00 is allowed as an end). A day may appear in several sections, and the ranges of one volunteer may overlap or touch each other. An empty string means a volunteer with no availability.
A range covers the minutes from its start up to, but not including, its end. A volunteer counts once in any minute they are covered, however many of their ranges include it.
Report the blocks of time in which at least k different volunteers are available. A block is maximal: it stretches over every consecutive minute of the same day that has at least k volunteers, even if the volunteers change along the way. Blocks never continue across midnight, so one ending at 24:00 and one starting at 00:00 the next day are separate. Drop blocks shorter than min_minutes minutes (a block of exactly min_minutes is kept).
Input: availability, a list of strings; k and min_minutes, integers.
Output: a list of strings "<Day> HH:MM-HH:MM", one per block, ordered by day of the week (Mon first) and then by start time. If there are no blocks, return [].
Example 1
- Input:
- [["Mon 09:00-12:00,14:00-17:00;Tue 10:00-11:00","Mon 10:00-15:00","Mon 11:00-13:00;Tue 10:30-12:00"],2,30]
- Output:
- ["Mon 10:00-13:00","Mon 14:00-15:00","Tue 10:30-11:00"]
- Explanation
- With k = 2, Mon has two people at 10:00-11:00 (the first two volunteers) and three at 11:00-12:00, then two again until 13:00 (the pair changes at each boundary, but the block stays unbroken), so it is one range, 10:00-13:00. 14:00-15:00 is the other time two overlap. On Tue the only overlap is 30 minutes long, exactly min_minutes, which is kept.
Example 2
- Input:
- [["Wed 09:00-11:00,10:00-12:00,12:00-13:00","Wed 12:00-14:00;Wed 08:00-09:30"],2,1]
- Output:
- ["Wed 09:00-09:30","Wed 12:00-13:00"]
- Explanation
- Each string is one volunteer, and a volunteer counts once even when their ranges overlap or touch: the first volunteer is available Wed 09:00-13:00 in total, never counting twice. The other volunteer is free 08:00-09:30 and 12:00-14:00, so two people are present only 09:00-09:30 and 12:00-13:00.
Example 3
- Input:
- [["Sun 22:00-24:00","Sun 00:00-01:00","Fri 23:00-24:00;Sat 00:00-00:45","Fri 08:00-09:00;Sat 00:45-02:00"],1,60]
- Output:
- ["Fri 08:00-09:00","Fri 23:00-24:00","Sat 00:00-02:00","Sun 00:00-01:00","Sun 22:00-24:00"]
- Explanation
- Ranges never join across midnight, so Fri 23:00-24:00 and Sat 00:00-02:00 are separate even though they touch; Sat 00:00-02:00 is one range because two different volunteers cover it back to back. Short stretches are dropped after merging, and the days are in week order, Mon first.
Constraints
0 <= availability.length <= 30; each string holds at most 30 ranges1 <= k <= 30;1 <= min_minutes <= 1440- Times are
"HH:MM"from00:00to24:00; in every range the start is strictly before the end