Find the next time, at or after a given clock time, whose HH:MM representation is a palindrome.
Palindromic Times
You are given a time on a 24-hour clock in HH:MM format.
A time is called palindromic if the four digits of the clock time read the same forward and backward, ignoring the colon. For example, 05:50 is palindromic because 0550 reversed is also 0550.
Your task is to find the earliest palindromic time that is not earlier than the given time.
If the given time is already palindromic, it should be considered the answer.
Notes
- Times use the 24-hour format from
00:00to23:59. - The answer must be a valid time on the same clock.
- If needed, wrap around to the next day.
Input Format
- A single line containing a time string in
HH:MMformat.
Output Format
- Print the earliest palindromic time that is greater than or equal to the given time.
Constraints
00 <= HH <= 2300 <= MM <= 59- Input is guaranteed to be a valid 24-hour time.
Example 1
Input
05:39
Output
05:50
Explanation
05:50 is the first time at or after 05:39 whose digits form a palindrome.
Example 2
Input
15:51
Output
15:51
Explanation
The given time is already palindromic, so it is the answer.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.