Update indices of X , Y , Z ;
for ( int i = 0 ; i < n ; i ++ ) { if ( mp . containsKey ( s . charAt ( i ) ) ) { mp . get ( s . charAt ( i ) ) . add ( i ) ; } else { mp . put ( s . charAt ( i ) , new ArrayList < Integer > ( Arrays . asList ( i ) ) ) ; } }