Write a function to check if two strings are rotations of each other.
MediumProblem Statement
Write a function to check if two strings are rotations of each other.
Sample Input
Hardcoded strings: "abcd" and "cdab"
Sample Output
cdab is a rotation of abcd
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
fun areRotations(str1: String, str2: String): Boolean {
// Add your code here to check if the strings are rotations
}
fun main() {
val str1 = "abcd"
val str2 = "cdab"
if (areRotations(str1, str2)) {
println("$str2 is a rotation of $str1")
} else {
println("$str2 is not a rotation of $str1")
}
}
Input
Hardcoded strings: "abcd" and "cdab"
Expected Output
cdab is a rotation of abcd