Baseline Strings · Easy O(N^2) · O(N)
A museum display carousel steps leftward one item at a time, and curators photograph its arrangement at random moments. An archivist must confirm whether a photographed arrangement is just the reference lineup after some number of steps — the same items, same cyclic order, different starting point. Different lengths or a genuinely different cyclic order mean the photo shows something else entirely.
Input: Two strings s (the reference lineup) and goal (the photographed arrangement).
Output: true when goal can be reached from s by repeatedly taking its first character and appending it to the end, false otherwise.
1 <= s.length, goal.length <= 100s and goal consist of lowercase English lettersInput: {"s":"abcde","goal":"cdeab"}
Output: true
Shifting a, b off the front and onto the back lands exactly on the photographed arrangement.
Input: {"s":"abcde","goal":"abced"}
Output: false
Same length, same letters, but no rotation reproduces the swapped tail.