Given a string str which stores the time in the 24 hours fomat as “HH:MM”. The task is to find the minimum minutes needs to be added to make time palindromic.
Input: str = “05:39”
Explanation: It takes 11 minutes for minute value to become 50, 05:50 is a palindromic time
Input: str = “13:31”
Explanation: Since, 13:31 is already palindromic therefore, 0 minutes is required
The idea is to greedily increment the minute value until 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 value 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 :
Time Complexity: O(1)
Auxiliary Space: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Make palindromic string non-palindromic by rearranging its letters
- Minimum cuts required to convert a palindromic string to a different palindromic string
- Minimum number of bracket reversals needed to make an expression balanced
- Minimum number of Appends needed to make a string palindrome
- Find minimum operations needed to make an Array beautiful
- Minimum number of bracket reversals needed to make an expression balanced | Set - 2
- Minimum number of letters needed to make a total of n
- Find the time which is palindromic and comes after the given time
- Minimum palindromic subarray removals to make array Empty
- Minimum Count of Bit flips required to make a Binary String Palindromic
- Minimum size substring to be removed to make a given string palindromic
- Longest Palindromic Substring using Palindromic Tree | Set 3
- Minimum steps needed to cover a sequence of points on an infinite grid
- Minimum numbers needed to express every integer below N as a sum
- Find minimum number of Log value needed to calculate Log upto N
- Minimum amount of lamps needed to be installed
- Minimum number of steps needed to remove the substring K from given string
- Make a palindromic string from given string
- Make the string lexicographically smallest and non palindromic by replacing exactly one character
- Make the string lexicographically smallest and non palindromic by swapping of adjacent pair of characters
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.