text: Check if K palindromic strings can be formed from a given string | C # program to check whether the string is K palindrome or not ; Function to check whether the string is K palindrome or not ; Map to frequency of character ; Check when k is given as same as length of string ; Storing the frequency of every character in map ; If K is greater than size of then return false ; Check that number of character having the odd frequency ; If k is less than number of odd frequency character then it is again false otherwise true ; Driver Code
code: using System ; using System . Collections . Generic ; class GFG { static bool can_Construct ( String S , int K ) { Dictionary < char , int > m = new Dictionary < char , int > ( ) ; int p = 0 ; if ( S . Length == K ) return true ; for ( int i = 0 ; i < S . Length ; i ++ ) if ( ! m . ContainsKey ( S [ i ] ) ) m . Add ( S [ i ] , 1 ) ; else m [ S [ i ] ] = m [ S [ i ] ] + 1 ; if ( K > S . Length ) return false ; else { foreach ( int h in m . Values ) { if ( h % 2 != 0 ) p = p + 1 ; } } if ( K < p ) return false ; return true ; } public static void Main ( String [ ] args ) { String S = " annabelle " ; int K = 4 ; if ( can_Construct ( S , K ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }