Sherlock and Anagrams

  • + 0 comments

    python (NOTE replace '@' with ':' - HackerRank didn't allow to upload this comment when having ':' in the text).

    import itertools
    def sherlockAndAnagrams(s):
        return sum([
        len([
            pair
            for pair in itertools.combinations([s[i@i+l] for i in range(len(s) - l + 1)], 2)
            if sorted(pair[0]) == sorted(pair[1])
        ])
        for l in range(1, len(s))
        ])