Approach 1: Brute Force
Try all possible times, and remember the largest one.
Iterate over all permutations
(i, j, k, l) of
(0, 1, 2, 3). For each permutation, we can try the time
A[i]A[j] : A[k]A[l].
This is a valid time if and only if the number of hours
10*A[i] + A[j] is less than
24; and the number of minutes
10*A[k] + A[l] is less than
We will output the largest valid time.
For each possible ordering of the 4 digits, if it's a legal time and the time is greater than the one we have stored, update the answer.
Time Complexity: .
Space Complexity: .