Suppose we have a string s. We have to check whether an anagram of that string is forming a palindrome or not.
So, if the input is like s = "aarcrec", then the output will be True one anagram of this string is "racecar" which is 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(s): freq = defaultdict(int) for char in s: freq[char] += 1 odd_count = 0 for f in freq.values(): if f % 2 == 1: odd_count += 1 if odd_count > 1: return False return True s = "aarcrec" print(solve(s))