All problems
0073EasyStringString Matching

Carousel Alignment

Tracked in this browser only
Write code

Trains the technique from

LeetCode 796Rotate String

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A baggage carousel is a closed loop of slots, each stencilled with one lowercase letter. A scanner sits at one point of the loop and reads the letters clockwise from wherever the loop currently rests, producing the string belt.

Nudging the carousel forward by one slot moves the letter that was under the scanner to the far end of the reading and shifts everything else one place earlier. So a nudge turns "cargo" into "argoc".

Return true when some number of nudges, possibly zero, makes the scanner's reading equal target, and false otherwise.

Examples

Example 1

Input
belt = "loops", target = "opslo"
Output
true

Two nudges send l and o to the back of the reading, which lands exactly on the target.

Example 2

Input
belt = "loops", target = "loosp"
Output
false

The target uses the same five letters, but swapping the last two is not something nudging the loop can do.

Example 3

Input
belt = "loops", target = "ops"
Output
false

Nudging never removes a slot, so a shorter target can never be reached.

Constraints

  • 1 <= belt.length, target.length <= 100
  • belt and target contain lowercase English letters only

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def can_align_carousel(belt: str, target: str) -> bool:
Java
public boolean canAlignCarousel(String belt, String target)
September 7
Apply