Circular Shift

Published by bangyen in

Write a function that takes two arrays (arr1 and arr2) and an int n, and returns true if the second array equals the first array shifted by n positions. Otherwise, return false.

Examples

circular_shift([1, 2, 3, 4], [3, 4, 1, 2], 2) ➞ true

circular_shift([1, 1], [1, 1], 6) ➞ true

circular_shift([0, 1, 2, 3, 4, 5], [3, 4, 5, 2, 1, 0], 3) ➞ false

Notes

  • The two lists will have the same length.
  • n can be a negative value.
Watch a quick demo on how Edabit works.