Ctrl K

Match After Shifts

Easy
You are given two strings source and target. In one operation you take the first letter of source and move it to the end. For example, one operation turns "lemon" into "emonl". Return True if applying the operation any number of times (zero included) can turn source into target, and False otherwise.
Example 1
source="python", target="honpyt" → True

Move 'p', then 'y', then 't' from the front to the back: python → ythonp → thonpy → honpyt.

Example 2
source="stack", target="tacks" → True

Moving 's' to the back once gives 'tacks'.

Example 3
source="queue", target="queues" → False

A shift never changes the length, and the lengths differ.

Constraints
  • 1 ≤ len(source), len(target) ≤ 100
  • Both strings consist of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsWhere the Fragment Starts EasyWhole Copies of a Block EasyWords Hidden in Others EasyFirst Word With a Given Beginning EasyLongest Back-to-Back Run Easy
loading Python…
Input
source="python", target="honpyt"
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 114 tests on the server, hidden ones included.