176. Check if String is a Rotation of Another

EasyStringString

Given two strings s and goal, return 'true' if goal is a rotation of s.

A rotation means you can rotate s by k positions (0 ≤ k < len(s)) to obtain goal.

Both strings must have the same length.

Input: Two comma-separated strings: s and goal.

Output: Return 'true' if goal is a rotation of s, otherwise 'false'.

Examples

Example 1
Input: abcde,cdeab
Output: true
Explanation: Rotating 'abcde' by 2 gives 'cdeab'.
Example 2
Input: abcde,abced
Output: false
Explanation: No rotation of 'abcde' gives 'abced'.
Example 3
Input: abc,abc
Output: true
Explanation: Zero rotation.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →