← All coding problems
Check String Rotation
easyPlacement Coding+10 XPTime limit 2s
String b is a rotation of string a if you can move some characters from the front of a to its back and get b. "llsski" is a rotation of "skills" ("ski" moved to the end), but "sklisl" is not.
Input:
- line 1: string
a - line 2: string
b
Both contain only lowercase letters.
Output: true if b is a rotation of a, otherwise false.
Constraints: 1 ≤ length of each ≤ 10⁵.
Think about it: every rotation of a appears inside a + a. So b is a rotation exactly when the lengths match and b is a substring of a + a.
Sample input 1
skills llsski
Sample output 1
true
Sample input 2
abcd acbd
Sample output 2
false
Read input from standard input and print the answer to standard output. Your code runs in a secure sandbox against the samples (Run) and hidden tests (Submit).