Ctrl K

Setting the Clock Forward

Easy
A digital clock shows the time shown, while the real time is actual. Both are 24-hour times in the format "HH:MM" (from 00:00 to 23:59), and shown is not later than actual. The clock cannot go backwards. It has four buttons: "+1 min", "+5 min", "+15 min" and "+60 min", each of which can be pressed any number of times. Return the fewest presses that make the clock show actual.
Example 1
shown="08:10", actual="09:40" → 3

The gap is 90 minutes: +60, +15, +15, three presses.

Example 2
shown="21:58", actual="22:05" → 3

The gap is 7 minutes: +5, +1, +1.

Example 3
shown="06:00", actual="06:00" → 0

The clock is already right.

Constraints
  • shown and actual are valid times in the format "HH:MM"
  • shown ≤ actual
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPalindrome From Letter Tiles EasyPalindrome With One Eraser Stroke EasyRise and Fall Lineup EasyMost Even L/R Pieces EasyTime Behind the Smudges Easy
loading Python…
Input
shown="08:10", actual="09:40"
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 138 tests on the server, hidden ones included.