Next Closest Time - Problem
Given a time represented in the format "HH:MM", form the next closest time by reusing the current digits. There is no limit on how many times a digit can be reused.
You may assume the given input string is always valid. For example, "01:34", "12:09" are all valid. "1:34", "12:9" are all invalid.
Return the next closest time in the same format "HH:MM".
Input & Output
Example 1 — Basic Case
$
Input:
time = "19:34"
›
Output:
"19:41"
💡 Note:
The next closest time using digits {1,3,4,9} is 19:41. We increment the minutes from 34 to 41 using available digits.
Example 2 — Wrap to Next Hour
$
Input:
time = "23:59"
›
Output:
"22:22"
💡 Note:
Available digits are {2,3,5,9}. Since no valid time exists after 23:59 on same day using these digits, we wrap to next day with smallest time: 22:22.
Example 3 — Same Digits
$
Input:
time = "00:00"
›
Output:
"00:00"
💡 Note:
Only digit 0 is available. The next closest time using only 0s is still 00:00 (wraps around).
Constraints
- time.length == 5
- time is in the format "HH:MM"
- 0 ≤ HH ≤ 23
- 0 ≤ MM ≤ 59
Visualization
Tap to expand
Understanding the Visualization
1
Input
Time string in HH:MM format with available digits
2
Process
Find next time using only these digits
3
Output
Return next closest valid time
Key Takeaway
🎯 Key Insight: Reuse only the available digits from input time to minimize the next valid time increment
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code