Ninja has his own philosophy. He thinks that if his watch started showing next closet time he will be able to do all his work on time. As if his watch shows next closet time, then he would think that the deadline is near and he will be able to do his work before deadline.
So your task is to write a code that can return the next closet time you are given a time represented in the format “HH: MM” by using the current digits. There is no limit on how many times a digit can be used.
Input Format:
The first line of input contains a ‘T’ number of test cases.
The first line of input of each test case contains a string 'TIME', which represents the time in “HH: MM” format.
Output Format:
For each test case, return the string which is the next closest time to the given string.
Note:
You are not required to print anything explicitly. It has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 100
| TIME | = 5
Time Limit: 1 sec
2
19:34
23:59
19:39
22:22
Test Case 1:
According to this test case string given is ‘19:34’ so the possible time combination is:
For the same day, the next closet time is ‘19:39’, ‘19:41’, 19:43’
For the next day, the next closet time is ‘11:11’, ‘11:13’, ‘11:14’, ‘11:19’, ‘11:31’, ‘11:34’, ‘11:41’, ‘11:43’and so on.
So next time which is near to 19:34 is 19:39 so we return this as our answer.
Test Case 2:
According to this test case string given is ‘23:59’ so possible time combination is only possible for the next day i.e ‘22:22’, ‘22:23’, ‘22:25’, ‘22:29’, ‘22:32’and so on.
So next time which is near 23:59 is 22:22 so we return this as our answer.
2
11:34
07:24
11:41
07:27
Can you find all possible combinations of time by using these given 4 digits?
O(1), constant time complexity.
As maximum, our loop will run maximum for 24*60=1440 making complexity as O(1440).
O(1), constant space complexity.
As we are using constant space.