Find if string is K | C # program to find if String is K - Palindrome or not using all characters exactly once ; When size of String is less than k ; When size of String is equal to k ; When size of String is greater than k to store the frequencies of the characters ; To store the count of characters whose number of occurrences is odd . ; Iterating over the map ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void iskPalindromesPossible ( String s , int k ) { if ( s . Length < k ) { Console . Write ( " Not ▁ Possible " + " STRNEWLINE " ) ; return ; } if ( s . Length == k ) { Console . Write ( " Possible " + " STRNEWLINE " ) ; return ; } Dictionary < int , int > freq = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < s . Length ; i ++ ) if ( freq . ContainsKey ( s [ i ] ) ) { freq [ s [ i ] ] = freq [ s [ i ] ] + 1 ; } else { freq . Add ( s [ i ] , 1 ) ; } int count = 0 ; foreach ( KeyValuePair < int , int > it in freq ) { if ( it . Value % 2 == 1 ) count ++ ; } if ( count > k ) Console . Write ( " No " + " STRNEWLINE " ) ; else Console . Write ( " Yes " + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { String str = " poor " ; int K = 3 ; iskPalindromesPossible ( str , K ) ; str = " geeksforgeeks " ; K = 10 ; iskPalindromesPossible ( str , K ) ; } }