Rotation Check
Given two strings, check if they are rotations of each other. Return 'true' if they are rotationally equivalent, otherwise return 'false'.
[ "abcde", "deabc" ]
Explanation. The string 'deabc' is a rotation of 'abcde' starting from index 3.
[ "hello", "lohel" ]
Explanation. The string 'lohel' is a rotation of 'hello' starting from index 3.
[ "coding", "ingcod" ]
Explanation. The string 'ingcod' is a rotation of 'coding' starting from index 3.
[ "test", "estt" ]
Explanation. Although 'estt' contains the same characters as 'test', the arrangement does not match any rotation of 'test'.
Follow-up: Can you improve your solution to run in O(n) time where n is the length of the longest string?
The input strings will only contain lower case alphabets and will have at least 1 character.
- Views
- 3