15% off all plans & roadmaps Use code
See plansLeetCode 796 · Solution & editorial
Given two strings s and goal, return true if and only if s can become goal after some number of shifts on s.
Rotate String is a String Manipulation Patterns problem, in the Naive / KMP / Rabin-Karp subpattern. The pattern covers palindrome checking, anagram detection, pattern matching, and string conversion
Master string matching algorithms including naive search, KMP pattern matching, and Rabin-Karp hashing.
The reference solution runs in O(n) time and O(1) space.
Rotate String has been reported in interviews at Amazon, Microsoft, Oracle.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Rotate String is a String Manipulation Patterns problem, in the Naive / KMP / Rabin-Karp subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.