FastPrepFastPrep
Problem Brief

Cyclic Shift Pairs

INTERNOA
See Roblox online assessment and hiring insights

Like alwasy, feel free to check out source images for original problem statement. Thank U for your understanding~~~~~~

1Example 1

Input
a = [13, 5604, 31, 2, 13, 4560, 546, 654, 456]
Output
5
Explanation

There are 5 cyclic pairs of numbers - pairs which are equal to each other after cyclic shifts.

  • a[0] = 13 and a[4] = 13 (i = 0 and j = 4)
  • a[0] = 13 and a[4] = 13 (i = 0 and j = 4)
  • a[1] = 5604 and a[5] = 4560 (i = 1 and j = 5)
  • a[2] = 31 and a[4] = 13 (i = 2 and j = 4)
  • a[6] = 546 and a[7] = 654 (i = 6 and j = 7)

Note that a[6] = 546 and a[8] = 456 are not cyclic pairs - 546 can only be paired with cyclic shift of 546, 465 and 654.

Also, note that a[5] = 4560 and a[8] = 456 are not cyclic pairs because they have different number of digits.

public int shifOops(int[] a) {
  // write your code here
}
Input

a

[13, 5604, 31, 2, 13, 4560, 546, 654, 456]

Output

5

Sign in to submit your solution.