Distinct characters in the String with the help of set
HashSet < char > set = new HashSet < char > ( ) ; for ( int j = 0 ; j < S [ i ] . Length ; j ++ ) { if ( ! set . Contains ( S [ i ] [ j ] ) ) set . Add ( S [ i ] [ j ] ) ; } int c = set . Count ;