DSA problem
Rotate String
Given two strings s and goal, return true if and only if s can become goal after some number of shifts on s.
A shift on s consists of moving the leftmost character of s to the rightmost position. For example, if s = "abcde", then it will be "bcdea" after one shift.
In other words, you may rotate s by any amount (including zero), and the question asks whether one of those rotations equals goal. Note that both strings consist of lowercase English letters only, and a valid answer requires the two strings to have the same length.
Examples
Example 1
Input:
s = "abcde", goal = "cdeab"Output:
trueExplanation: Shifting "abcde" left twice produces "cdeab", so the answer is true.
Example 2
Input:
s = "abcde", goal = "abced"Output:
falseExplanation: No sequence of left shifts of "abcde" can produce "abced".
Constraints
- 1 <= s.length, goal.length <= 100
- s and goal consist of lowercase English letters.
3 hints and a full solution walkthrough with step-by-step visualizations are available in the practice editor.