LeetCode 796, Easy. Topics: String, String Matching. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 30 parametrized pytest cases, and a playground notebook:
Problem
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.
Examples
Constraints
- 1 <= s.length, goal.length <= 100
- s and goal consist of lowercase English letters.
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
Last modified on September 7, 2026