Suppose we have a string s, we have to check whether characters of the given string can be shuffled to make a palindrome or not.
So, if the input is like s = "raaecrc", then the output will be True as we can rearrange this to "racecar" which is a palindrome.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
from collections import defaultdict def solve(st) : freq = defaultdict(int) for char in st : freq[char] += 1 odd_count = 0 for i in freq.values(): if i % 2 == 1: odd_count = odd_count + 1 if odd_count > 1: return False return True s = "raaecrc" print(solve(s))