Function to check if all characters are distinct
static boolean ifAllDistinct ( String str ) { HashSet < Character > s = new HashSet < Character > ( ) ; for ( char c : str . toCharArray ( ) ) { s . add ( c ) ; } return s . size ( ) == str . length ( ) ; }