text: Count the number of strings in an array whose distinct characters are less than equal to M | C # implementation to count the number of strings in the array whose distinct characters is less than or equal to M ; Function to count the strings whose distinct characters count is less than M ; Loop to iterate over all the strings of the array ; Distinct characters in the String with the help of set ; Checking if its less than or equal to M ; Driver Code
code: using System ; using System . Collections . Generic ; class GFG { public static void distinct ( string [ ] S , int M ) { int count = 0 ; for ( int i = 0 ; i < S . Length ; i ++ ) { 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 ; if ( c <= M ) count += 1 ; } Console . Write ( count ) ; } public static void Main ( string [ ] args ) { string [ ] S = { " HERBIVORES " , " AEROPLANE " , " GEEKSFORGEEKS " } ; int M = 7 ; distinct ( S , M ) ; } }