text: Check if any permutation of string is a K times repeated string | C # implementation to check that the permutation of the given String is K times repeated String ; Function to check that permutation of the given String is a K times repeating String ; if length of String is not divisible by K ; Frequency Array ; Initially frequency of each character is 0 ; Computing the frequency of each character in the String ; Loop to check that frequency of every character of the String is divisible by K ; Driver Code
code: using System ; class GFG { static bool repeatingString ( String s , int n , int k ) { if ( n % k != 0 ) { return false ; } int [ ] frequency = new int [ 123 ] ; for ( int i = 0 ; i < 123 ; i ++ ) { frequency [ i ] = 0 ; } for ( int i = 0 ; i < n ; i ++ ) { frequency [ s [ i ] ] ++ ; } int repeat = n / k ; for ( int i = 0 ; i < 123 ; i ++ ) { if ( frequency [ i ] % repeat != 0 ) { return false ; } } return true ; } public static void Main ( String [ ] args ) { String s = " abcdcba " ; int n = s . Length ; int k = 3 ; if ( repeatingString ( s , n , k ) ) { Console . Write ( " Yes " + " STRNEWLINE " ) ; } else { Console . Write ( " No " + " STRNEWLINE " ) ; } } }