Determine whether one string can be rotated to become another string.
Given two strings s and goal, determine whether goal can be obtained by rotating s any number of positions.
A rotation moves some prefix of the string to the end while keeping the relative order of all characters the same. You may rotate the string zero or more times.
Return true if goal is reachable from s, otherwise return false.
abcde -> cdeababcde -> deabcs and goal.true if goal is a rotation of s, otherwise false.s.length != goal.length, the answer is immediately false.Example 1
Input
s = "abcde", goal = "cdeab"
Output
true
Explanation
Rotating abcde left by 2 positions gives cdeab.
Example 2
Input
s = "abcde", goal = "abced"
Output
false
Explanation
No rotation of abcde can produce abced.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.