Description
Solutions
Count Cyclic Pairs
🤘 INTERN

tomtom's note: Feel free to check out the source image below for the original problem statement :)

Once upon a time, there was a magical array of numbers, each with its own unique set of digits. These numbers had a secret ability: they could rearrange themselves by performing a special move called a "cyclic shift." This meant they could take some digits from the end and move them to the front, while shifting all the other digits over in the same order. If two numbers could be transformed into each other through this shifting magic, they were known as "cyclic pairs."

Example 1:

Input:  a = [13, 5604, 31, 2, 13, 4560, 546, 654, 456]
Output: 5
Explanation:
Let's dive into the pairs that were discovered: The first number, 13, found its twin in 31. By shifting 31, it transformed into 13, making them a cyclic pair. The same 13 found another match with the fourth number in the array—another 13. No shifting was needed here; they were already identical. The number 31, which was once a partner to 13, found itself paired again with another 13 later in the array. With a quick shift, they became a perfect match. The number 5604 met its match in 4560. By shifting the digits around, 5604 could become 4560, sealing their bond as a cyclic pair. Finally, 546 discovered its twin in 654. A little bit of shifting magic, and they were a perfect match. In the end, there were 5 magical pairs in the array, each one connected by the special bond of a cyclic shift. However, not all numbers were lucky. For instance, 546 couldn’t match with 456, even though they seemed close. The digits just didn’t line up the right way, and they couldn’t become a pair. Similarly, 4560 and 456 were from different worlds, with a different number of digits, so their paths never crossed. And so, the magical array revealed its secrets, showing us that in a world of numbers, sometimes, all it takes is a little shift to find your perfect match.
Constraints:
    🌱
Thumbnail 0
Thumbnail 1
Testcase

Result
Case 1

input:

output: