1175. Minutes Until
A bus stop display shows how long remains until the next departure. You are given current, the time now, and target, the departure time, both as 24-hour clock strings "HH:MM" with two digits for each part.
Return the number of minutes you must wait, counting forward in time from current to the next occurrence of target. If the target clock time has already passed today, the wait continues past midnight into the next day, so for example 23:50 to 00:10 is 20 minutes. When the two times are identical the wait is 0 minutes, never a full day of 1440.
Converting both times to minutes since midnight and taking the difference modulo 1440 solves it in constant time and space.
Example 1
- Input:
- current = "09:15", target = "10:45"
- Output:
- 90
- Explanation:
From 09:15 to 10:45 is 90 minutes.
Example 2
- Input:
- current = "23:50", target = "00:10"
- Output:
- 20
- Explanation:
The wait runs past midnight: 10 minutes to 24:00 plus 10 more.
Example 3
- Input:
- current = "06:30", target = "06:30"
- Output:
- 0
- Explanation:
Equal times are 0 minutes apart, not a full day.
Constraints
Both strings are valid times between 00:00 and 23:59
How this problem is judged
- Answers
- Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
Expected complexity
- Time
- O(1)
- Space
- O(1)