Flip Digits Equivalent Pairs

Company: Visa_17sep

Difficulty: medium

Problem Statement

Flip Digits Equivalent Pairs A giant circuit board carries light sequences, and each sequence is written down as a non-negative integer. Reversing a sequence means reversing the digits of that integer, so the operation flipDigits(x) takes the decimal digits of x , writes them in the opposite order, and drops the leading zeros the reversal may have created. For example: flipDigits(5070) = 705 -- the reversal is 0705 , and only the leading zero disappears; the inner zero stays. flipDigits(800) = 8 flipDigits(123) = 321 flipDigits(0) = 0 Two sequences are called equivalent when combining them gives the same total no matter which one starts the combination. You are given an array arr of n non-negative integers. Implement solution(arr) , which returns the number of pairs of indices (i, j) with i <= j such that arr[i] + flipDigits(arr[j]) == arr[j] + flipDigits(arr[i]) Input Format The first line contains a single integer n -- the number of light sequences. The second line contains n spac