You are viewing a single comment's thread. Return to all comments →
from collections import Counter def anagram(s): n = len(s) if n % 2 == 1: return -1 a = s[:n//2] b = s[n//2:] freq_a = Counter(a) freq_b = Counter(b) changes = 0 for char in freq_a: if freq_a[char] > freq_b.get(char, 0): changes += freq_a[char] - freq_b.get(char, 0) return changes
Seems like cookies are disabled on this browser, please enable them to open this website
Anagram
You are viewing a single comment's thread. Return to all comments →