text: Check if characters of a given string can be used to form any N equal strings | C # program for the above approach ; Function to check if the freq of any character is divisible by N ; Stores the frequency of characters ; If frequency of a character is not divisible by n ; If no character has frequency at least N ; Driver Code ; Function Call
code: using System ; using System . Collections . Generic ; class GFG { static bool isSame ( String str , int n ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( mp . ContainsKey ( str [ i ] - ' a ' ) ) { mp [ str [ i ] - ' a ' ] = mp [ str [ i ] - ' a ' ] + 1 ; } else { mp . Add ( str [ i ] - ' a ' , 1 ) ; } } foreach ( KeyValuePair < int , int > it in mp ) { if ( ( it . Value ) >= n ) { return true ; } } return false ; } public static void Main ( String [ ] args ) { String str = " ccabcba " ; int n = 4 ; if ( isSame ( str , n ) ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }