We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I took a slightly less compact approach while leveraging defaultdict, which inits each letter to zero before it's counted. The count of each letter in the first string is totaled, then the count of each letter in the second string is subtracted. Any count that is nonzero represents the net surplus or deficit of letters between the two strings, the total of which is the answer.
(It is trivial to then show exactly what letters were in that counted symmetric difference set.)
Making Anagrams
You are viewing a single comment's thread. Return to all comments →
I took a slightly less compact approach while leveraging defaultdict, which inits each letter to zero before it's counted. The count of each letter in the first string is totaled, then the count of each letter in the second string is subtracted. Any count that is nonzero represents the net surplus or deficit of letters between the two strings, the total of which is the answer.
(It is trivial to then show exactly what letters were in that counted symmetric difference set.)