easy +10 pts

Is rotation of another string

Check if one string is a rotation of another string efficiently.

Write a function `is_rotation(s1: str, s2: str) -> bool` that returns `True` if the string `s1` is a rotation of the string `s2`, and `False` otherwise. A string is a rotation of another if we can shift the characters of one string left (or right) by any number of positions to obtain the other string. For example, `"waterbottle"` is a rotation of `"erbottlewat"` (shift left by 3). Your function should handle edge cases: an empty string is a rotation of an empty string (since no shift is needed). Consider the definition of rotation carefully for strings of different lengths. You must implement the function yourself without using extra libraries beyond the standard Python functions.

Constraints

Input strings consist of printable ASCII characters. Lengths are between 0 and 100,000. The function should be O(n) time and O(n) space (or better) in the worst case.

Example

```python
>>> is_rotation("abc", "bca")
True
>>> is_rotation("abc", "acb")
False
>>> is_rotation("", "")
True
>>> is_rotation("a", "a")
True
```
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Consider concatenating one string with itself and checking if the other string is a substring.
Remember to check if the two strings have the same length first.
The empty string is a rotation of itself.
In Python, you can use `in` to check substring membership.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.