Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
The condition can be rearranged to (nums[i] - rev(nums[i])) == (nums[j] - rev(nums[j])).
Transform each nums[i] into (nums[i] - rev(nums[i])). Then, count the number of (i, j) pairs that have equal values.
Keep a map storing the frequencies of values that you have seen so far. For each i, check if nums[i] is in the map. If it is, then add that count to the overall count. Then, increment the frequency of nums[i].