Problems > Rotation of Each Other > Editorial

Rotation of Each Other — Solution & Editorial

Back to the Problem

B is a rotation of A exactly when the lengths match and B occurs inside A + A.

Complexity: O(|A|) with linear string search (naive search also fits these limits)