Before every performance, the stage manager's countdown clock must be advanced from whatever time it currently displays to the exact cue time written on the show's timing sheet. The clock has exactly four nudge buttons, which move the displayed time forward by 1, 5, 15, or 60 minutes respectively, wrapping back around to 00:00 after 23:59. Given the clock's current display and the required cue time, determine the fewest button presses needed to reach the cue time exactly (the clock only ever moves forward in time, and may wrap past midnight).
Line 1: the current time as a string HH:MM (24-hour clock, 00 <= HH <= 23, 00 <= MM <= 59).
Line 2: the target cue time as a string HH:MM in the same format.
A single integer: the minimum number of nudges required to advance the clock from the current time to the cue time.
HH:MM format.Example 1
Input
02:30 04:35
Expected
3
Explanation
The gap from 02:30 to 04:35 is 125 minutes. Two +60 nudges cover 120 minutes and one +5 nudge covers the remaining 5 minutes, for 3 presses total, which is minimal since no combination of the four sizes reaches 125 in fewer presses.
Example 2
Input
11:00 11:01
Expected
1
Explanation
The gap from 11:00 to 11:01 is exactly 1 minute, so a single +1 nudge is enough.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →