Problem Statement
A description of the problem can be found on Hackerrank.
Solution
I created solution in:
All solutions are also available on my GitHub.
Scala
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
object RotateString extends App { val lines = io.Source.stdin.getLines().toList val n = lines.head.toInt val strings = lines.tail strings.foreach(s => println(rotations(s, 0).mkString(" ")) ) def rotate(s: String): String = { s.tail + s.head } def rotations(s: String, n: Int): List[String] = { if(n == s.length) Nil else rotate(s) :: rotations(rotate(s), n + 1) } } |