Rotate String

Given two strings s and goal, return true if and only if s can become goal after some number of shifts. A shift moves the leftmost character of s to the rightmost position, so "abcde" becomes "bcdea".

30:00

Rotate String
easy
Free written solution
Topics
Companies

Given two strings s and goal, return true if and only if s can become goal after some number of shifts. A shift moves the leftmost character of s to the rightmost position, so "abcde" becomes "bcdea".

Example 1:
Input: {"s":"abcde","goal":"cdeab"}
Output: true
Constraints:
  • 1≤s.length,goal.length≤1001 \leq s.\text{length}, \text{goal.length} \leq 100

  • s and goal consist of lowercase English letters.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"s":"abcde","goal":"cdeab"}

A shift only moves characters around, so it never changes the length. Compare len(s) = 5 with len(goal) = 5.

s (length 5)

a
b
c
d
e

goal (length 5)

c
d
e
a
b
Variables
VariableValue
len(s)5
len(goal)5
DepthFunction Call
Stack empty
0/5