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'm not sure, but I think your hash scheme is not wholly valid.
I think it could have a collision between two sets of letters wherein one has:
(37 of a single letter, lets say 'b')
and the other has
(a single of a letter that is one higher than the previous letter, so 'c')
Because of the way that you modify the hashcode.
You could skirt around this by tracking the number of items in a count. Or by using the products of unique prime numbers (See Fundamental Theorem of Arithmetic)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and Anagrams
You are viewing a single comment's thread. Return to all comments →
I'm not sure, but I think your hash scheme is not wholly valid.
I think it could have a collision between two sets of letters wherein one has:
(37 of a single letter, lets say 'b')
and the other has
(a single of a letter that is one higher than the previous letter, so 'c')
Because of the way that you modify the hashcode.
You could skirt around this by tracking the number of items in a count. Or by using the products of unique prime numbers (See Fundamental Theorem of Arithmetic)