Strings String basics
128. Rotate String
You are given two strings s and goal. A shift moves the first letter of s to its end. For example, one
shift turns "lemon" into "emonl", and a second shift turns that into "monle".
Return true if some number of shifts turns s into goal, and false otherwise. Zero shifts counts too,
so when s already equals goal, the answer is true.
Example 1
Input: s = "water", goal = "terwa"
trueExplanation: One shift gives "aterw", and a second shift gives "terwa".
Example 2
Input: s = "listen", goal = "silent"
falseExplanation: Both words use the same letters, but none of the six shifts of "listen" spells "silent".
Example 3
Input: s = "aaa", goal = "aa"
falseExplanation: A shift never changes the length of s, so it can never become a shorter string.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ s.length, goal.length ≤ 105sandgoalhold lowercase English letters only.
Clarifying questions
What you would ask an interviewer before writing any code.