Iterate to minimum possible time
while ( hr >= 0 ) { int h0 = hr / 10 , h1 = hr % 10 ; int m0 = m / 10 , m1 = m % 10 ; int s0 = s / 10 , s1 = s % 10 ; int p = 0 ; vector < int > arr { h0 , h1 , m0 , m1 , s0 , s1 } ;