Sherlock and Anagrams

  • + 0 comments

    I thought to use a double for loop, so we start from every position, grow every size of substring until end of string, sort it, and store the substring. When we find a pair, we count up.

    cdcd expected output=5. Why? substring sorted their count when more than 1: c:2 d:2 cd: 3