Night Shift Pay Minutes
Medium · strings
A bakery keeps its staff rota as one line of text, log. The line holds one or more shifts separated by single commas, with no spaces. A shift looks like this:
HH:MM-HH:MM, a start time and an end time on a 24-hour clock (always two digits for the hour and for the minutes), for example09:15-12:40.- Optionally followed by
~and a whole number of minutes, for example22:00-06:30~45, which is an unpaid break taken during that shift.
If the end time is earlier than the start time, the shift runs past midnight and ends the next day. The start and end of a shift are never equal.
The paid time of a shift is its length in minutes minus its unpaid break (zero when there is none). Return the total paid minutes of all the shifts in the line.
Examples
Example 1
Input: log = "09:15-12:40,13:30-17:05,22:00-01:30"
Output: 630
The shifts last 205, 215 and 210 minutes. The last one crosses midnight.
Example 2
Input: log = "23:30-00:15~15"
Output: 30
The shift is 45 minutes long and 15 of them are an unpaid break.
Example 3
Input: log = "06:00-14:00~30,14:00-22:00~45"
Output: 885
Constraints
- 1 <= len(log) <= 10^5
- Every shift is written exactly in the format described, with hours from 00 to 23 and minutes from 00 to 59.
- A shift's start and end are different, and its unpaid break is shorter than the shift.