Minimum Number of Operations to Convert Time

You are given two strings current and correct representing two 24-hour times.

24-hour times are formatted as "HH:MM", where HH is between 00 and 23, and MM is between 00 and 59. The earliest 24-hour time is 00:00, and the latest is 23:59.

In one operation you can increase the time current by 1, 5, 15, or 60 minutes. You can perform this operation any number of times.

Return the minimum number of operations needed to convert current to correct.

Example 1
Inputcurrent = "02:30", correct = "04:35"
Output3
We can convert current to correct in 3 operations by adding 60 minutes twice and then 5 minutes once, and it cannot be done in fewer operations.
Example 2
Inputcurrent = "11:00", correct = "11:01"
Output1
We only have to add one minute to current, so the minimum number of operations needed is 1.

Constraints

  • current and correct are in the format "HH:MM"
  • current <= correct

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate