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
π±More Databricks problems
- Find First Anagram IndexPHONE SCREEN Β· Seen Apr 2026
- Minimize CommuteOA Β· Seen Apr 2026
- Difference Between Sums of PositionsSeen Sep 2024
- Longest Common Prefix of Number PairsSeen Sep 2024
- Subarray CountingSeen Sep 2024
- Write 'Y' on MatrixSeen Sep 2024
- Binary String RequestsSeen Aug 2024
- Bouncing Diagonal WeightsSeen Aug 2024