All problems

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:

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