Sherlock and Anagrams

  • + 1 comment

    Am I the only one who ended up using the binomial coefficient to work out how many pairs multiple occurances of the same string makes?

    Maybe I overcomplicated it but it makes the rest real simple: - Generate every substring - Make a unique ref for the characters in that substring by ordering and hashing it - Get the frequency of each has occurring - Sum the binomial coefficients of the occurances (> 1)