Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Write a function to check if two strings are rotations of each other.

Medium

Problem 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") } }
Log in or sign up to run or submit your code.Log inSign up
Input
Hardcoded strings: "abcd" and "cdab"
Expected Output
cdab is a rotation of abcd