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.
Probably not the best solution, but my Python3 approach is quite simple:
I am using window sliding - as two substring establishing an anagram has the same length - with different sizes:
from the shortest substring containing 1 string all the way up to n- 1
(e.g. by a 10-letter string: two overlapping 9-letter substring forming an anagram)
/ sidenote:
I am storing the resulting substrings on a "window-size level", to be able to compare its elements with each other later /
After we have these subtrings, we can count the frequency of each letter of the substrings with the help of the Counter method from the collections module.
We can compare the resulting dicts with each other --> if they are identical, increase the value of the counter variable - and finally, divide the value of this by 2, as each dict was compared twice.
Sherlock and Anagrams
You are viewing a single comment's thread. Return to all comments →
Hi all,
Probably not the best solution, but my Python3 approach is quite simple:
Let me know what you think or if you have suggestions for improvements.