Skip to content

Instantly share code, notes, and snippets.

@chenharryhua
Last active March 1, 2021 03:21
Show Gist options
  • Save chenharryhua/269163108a009d6538107be3e116b722 to your computer and use it in GitHub Desktop.
Save chenharryhua/269163108a009d6538107be3e116b722 to your computer and use it in GitHub Desktop.
/*
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