Skip to the code
cf.
+10 XP

#83 Same Playlist, Different Start

easy

A music app loops playlists, so two playlists are the same loop if one is the other rotated: it starts at a different song but keeps the same order.

Write isRotation(a, b) that returns true if b can be made by rotating a some number of places (including zero), and false otherwise. Song ids are whole numbers.

Example 1

Input: a = [1,2,3,4], b = [3,4,1,2]
Output: true

Rotating a by 2 gives b.

Example 2

Input: a = [1,2,3], b = [1,3,2]
Output: false

The songs are the same, but the order around the loop is different.

Constraints

  • 0 <= a.length, b.length <= 10^4
  • 0 <= a[i], b[i] <= 10^6
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).