Company: visa_9oct
Difficulty: medium
Light Sequence Puzzle Problem Description Imagine a group of young engineers trying to solve a puzzle involving sequences of lights on a circuit board. Each light sequence is represented by a non-negative integer, where reversing the digits in the integer represents reversing the light sequence. The reversal process flipDigits involves flipping the order of the digits and removing any leading zeros from the result. For instance: flipDigits(5070) = 705 flipDigits(800) = 8 flipDigits(321) = 123 Some special pairs of light sequences can be combined in a unique way that makes them equivalent, no matter which sequence starts the combination. Given an array of non-negative integers arr , the engineers need to calculate how many pairs (i, j) exist such that i <= j and arr[i] + flipDigits(arr[j]) == arr[j] + flipDigits(arr[i]) . Examples Example 1: Input: arr = [1, 20, 2, 11] Output: 7 Explanation: The output should be solution(arr) = 7 . For (i, j) = (0, 0) equality holds: 1 + 1 == 1 + 1 .