Skip to main content
Back to problems
Codeforces
Easy
Strings
Math
Simulation
Palindromic Times

Find the next time, at or after a given clock time, whose HH:MM representation is a palindrome.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement

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:00 to 23: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:MM format.

Output Format

  • Print the earliest palindromic time that is greater than or equal to the given time.

Constraints

  • 00 <= HH <= 23
  • 00 <= MM <= 59
  • Input is guaranteed to be a valid 24-hour time.
Examples
Sample cases returned by the problem API.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.