Traverse the String and store the last index of every character
for ( i = str . length ( ) - 1 ; i >= 0 ; i -- ) { if ( ! m . containsKey ( str . charAt ( i ) ) ) { m . put ( str . charAt ( i ) , i ) ; } } i = 0 ;