Learner Level
Implement the isRotationOfString method that checks whether one string can be formed by rotating the other string.
The input contains two strings first and second. Your task is to check whether second is a rotation of first.
A rotation keeps the same characters in the same circular order, but starts from a different position. For example, cdab is a rotation of abcd.
Two strings can be rotations only when their lengths are equal.
If second is a rotation of first, it will always appear inside first + first. For example, abcdabcd contains cdab.
Pseudocode:
function isRotationOfString(first, second):
if length(first) != length(second):
return false
doubled = first + first
if second exists inside doubled:
return true
return false