Strings Rotations
Medium Acceptance 43.83% Points 30.00
You are given two strings, s1 and s2, of equal lengths. Your task is to determine whether s2 can be obtained by rotating the characters of s1.
Note: The characters in the strings are in lowercase.
Examples
Example 1
Example 1
Input: s1 = "abcd", s2 = "cdab"
Output: true
Explanation: After 2 right rotations, s1 will become equal to s2.
Example 2
Example 2
Input: s1 = "aab", s2 = "aba"
Output: true
Explanation: After 1 left rotation, s1 will become equal to s2.
Hints
Hint 1
Expected Time Complexity: O(n)
Hint 2
Expected Space Complexity: O(n)
Constraints
- 1 <= s1.size(), s2.size() <= 10^5
- The characters in the strings are in lowercase.
Track your submissions
Please log in to review your progress and explore code submissions from other participants.
Unlock the full solution
Please log in to access detailed answers and explanations.
Join the discussion
Please log in to join conversations with other participants.