Company: Visa_17sep
Difficulty: medium
Flip Digits Equivalent Pairs Problem Description Imagine a group of young engineers trying to solve a puzzle involving sequences of lights on a giant 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 zeroes from the result. For instance: flipDigits(5070) = 705 flipDigits(800) = 8 flipDigits(123) = 321 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 pairs (i, j) such that i <= j are: For (i, j) = (0, 0) equality holds: 1