Find if string is K | Find if string is K - Palindrome or not using all characters exactly once Python 3 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
def iskPalindromesPossible ( s , k ) : NEW_LINE INDENT if ( len ( s ) < k ) : NEW_LINE INDENT print ( " Not ▁ Possible " ) NEW_LINE return NEW_LINE DEDENT if ( len ( s ) == k ) : NEW_LINE INDENT print ( " Possible " ) NEW_LINE return NEW_LINE DEDENT freq = dict . fromkeys ( s , 0 ) NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT freq [ s [ i ] ] += 1 NEW_LINE DEDENT count = 0 NEW_LINE for value in freq . values ( ) : NEW_LINE INDENT if ( value % 2 == 1 ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT if ( count > k ) : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT str1 = " poor " NEW_LINE K = 3 NEW_LINE iskPalindromesPossible ( str1 , K ) NEW_LINE str = " geeksforgeeks " NEW_LINE K = 10 NEW_LINE iskPalindromesPossible ( str , K ) NEW_LINE DEDENT