Problem ยท String
Count Cyclic Pairs
Learn this problemProblem statement
Two integers form a cyclic pair when they have the same number of decimal digits and one number can be obtained from the other by cyclically rotating its digits. A rotation may move any prefix to the end; zero rotations are allowed.
Given a, return the number of index pairs (i, j) with i < j for which a[i] and a[j] form a cyclic pair.
Function
solution(a: int[]) โ intExamples
Example 1
a = [13, 5604, 31, 2, 13, 4560, 546, 654, 456]return = 5The valid pairs are the three pairs among 13, 31, 13, plus (5604,4560) and (546,654). Numbers with different digit lengths cannot form a pair.
Constraints
๐ฑ