Check if the minute value is valid , if not valid then skip the current iteration , to check ' minute ' value flag is set to 0.
if ( ! isValid ( ( char ) m1 , ( char ) m2 , str , 0 ) ) { continue ; } if ( inRange ( i , j , L , R ) ) { displayTime ( i , j ) ; return ; } } } if ( inRange ( i , j , L , R ) ) displayTime ( i , j ) ; else System . out . println ( " - 1" ) ; }