Count Digit-Reversal Equivalent Pairs
Company: Hudson River Trading
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: trading - 网上海投 - 在线笔试
Quick Answer: This Hudson River Trading coding question tests hash-based counting for pairs that become equivalent after a digit-reversal transform. It is useful for practicing canonicalization, duplicate accounting, and careful handling of numeric string edge cases.
Constraints
- 0 <= arr.length <= 100000
- 0 <= arr[i] <= 10^9
- Pairs include i == j.
Examples
Input: ([1, 20, 2, 11],)
Expected Output: 7
Input: ([32, 332, 100],)
Expected Output: 4
Input: ([],)
Expected Output: 0
Input: ([0],)
Expected Output: 1
Input: ([10, 1],)
Expected Output: 2
Input: ([12, 21],)
Expected Output: 2
Input: ([100, 10, 1],)
Expected Output: 3
Input: ([123, 321, 111, 0],)
Expected Output: 5
Input: ([5, 50, 500, 5000],)
Expected Output: 4
Hints
- Rearrange the equation.
- Values with the same x - flipdigits(x) form valid pairs.
- For a group of size c, there are c * (c + 1) / 2 pairs with i <= j.