Problems > Rotation of Each Other

Rotation of Each Other

Difficulty: 1200 2000 ms 128 MB

strings

Is B a rotation of A (obtainable by moving a prefix of A to its end)?

Input: two lines: string A, then string B.

Output: YES or NO.

Constraints:

  • 1 ≤ |A|, |B| ≤ 104
  • lowercase letters

Sample Tests

Input 1
abcde
cdeab
Output 1
YES
Input 2
abc
acb
Output 2
NO

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.