Last active
March 1, 2021 03:21
-
-
Save chenharryhua/269163108a009d6538107be3e116b722 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://www.hackerrank.com/challenges/sherlock-and-anagrams/problem | |
*/ | |
def subs(str: String): List[String] = str.inits.flatMap(_.tails.toList.init.map(_.sorted)).toList | |
subs(str).groupBy(identity).map(x => x._2.size).map(x => (x-1)*x/2).sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment