If number of distinct substrings is not 2 , then not possible to replace a string .
if ( mp . size ( ) != 2 ) return false ; HashMap . Entry < String , Integer > entry = mp . entrySet ( ) . iterator ( ) . next ( ) ;