VOOZH about

URL: https://www.geeksforgeeks.org/dsa/minimum-minutes-needed-to-make-the-time-palindromic/

⇱ Minimum minutes needed to make the time palindromic - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Minimum minutes needed to make the time palindromic

Last Updated : 15 Jul, 2025

Given string str which stores the time in the 24 hours format as "HH: MM". The task is to find the minimum minutes that need to be added to make time palindromic.

Examples:

Input: str = "05:39" 
Output: 11 
Explanation: It takes 11 minutes for minute value to become 50, 05:50 is a palindromic time


Examples: 
Input: str = "13:31" 
Output:
Explanation: Since, 13:31 is already palindromic therefore, 0 minutes is required

Approach: 
The idea is to greedily increment the minute value until the time value becomes palindrome. Run a while loop to increment minute value and simultaneously check if hour value and minute value form a palindrome or not. 
While incrementing minute and hour values make sure to check for the base condition when the minute value is 60 and the hour value is 24.
Below is the implementation of the above approach :


Output: 
11

Time Complexity: O(1) 
Auxiliary Space: O(1)
 

Comment