Update ans
ans = Math . min ( ans , res [ str [ i ] ] ) ; } System . out . print ( ( ans + 1 ) + "NEW_LINE"); } private static char [ ] modstring ( char [ ] str ) { String s = " " ; boolean b = true ; for ( int i = 1 ; i < str . length ; ++ i ) { if ( str [ i - 1 ] != str [ i ] ) b = true ; if ( b ) { s += str [ i - 1 ] ; b = false ; } } return s . toCharArray ( ) ; }