Function to check if all characters are distinct
static bool ifAllDistinct ( String str ) { HashSet < char > s = new HashSet < char > ( ) ; foreach ( char c in str . ToCharArray ( ) ) { s . Add ( c ) ; } return s . Count == str . Length ; }