
Given ‘STR’ : #5:40
Maximum time possible can be : 15:40
The first line of input contains an integer ‘T’, the number of test cases.
The first line of each test case contains the string ‘STR’, representing the time.
For each test case, print a string representing the maximum possible time.
Output for each test case will be printed in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 50
The string ‘STR’ is always valid.
Time Limit : 1 sec
The basic idea is to find all the possible times and return the maximum time out of those using recursion.
Here is the algorithm :
HELPER(STR, RES, IDX): (‘HELPER’ function)
isPossible(STR): (Function to check whether the time is possible or not).
findMax(STR, RES): (Function to find the maximum of ‘STR’ and ‘RES’).
The basic idea is to assign digits to the string greedily to maximize the time. Assign all the digits individually to the string.
Here is the algorithm :