PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • medium
  • Hudson River Trading
  • Coding & Algorithms
  • Software Engineer

Count Digit-Reversal Equivalent Pairs

Company: Hudson River Trading

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: trading - 网上海投 - 在线笔试

Define `flipdigits(x)` as the integer produced by reversing the decimal digits of non-negative integer `x` and removing leading zeroes from the reversed result. Examples: ```text flipdigits(5070) = 705 flipdigits(800) = 8 flipdigits(123) = 321 ``` Given an array `arr` of non-negative integers, count how many pairs `(i, j)` satisfy `i <= j` and: ```text arr[i] + flipdigits(arr[j]) = arr[j] + flipdigits(arr[i]) ``` Return the count as an integer. Example 1: ```text arr = [1, 20, 2, 11] output = 7 ``` Example 2: ```text arr = [32, 332, 100] output = 4 ``` Constraints: - `0 <= arr.length <= 100000` - `0 <= arr[i] <= 10^9` - Count pairs with `i <= j`, so each element pairs with itself.

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.

For each non-negative integer x, flipdigits(x) reverses its decimal digits and removes leading zeroes. Count pairs (i, j) with i <= j such that arr[i] + flipdigits(arr[j]) = arr[j] + flipdigits(arr[i]).

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

  1. Rearrange the equation.
  2. Values with the same x - flipdigits(x) form valid pairs.
  3. For a group of size c, there are c * (c + 1) / 2 pairs with i <= j.
Last updated: Jul 2, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Count Length-3 Chat Substrings with a Vowel - Hudson River Trading (medium)
  • Simulate Alternating Stick Collection for a Nest - Hudson River Trading (medium)
  • Calculate Completion Time for a Single-Server Reactor Queue - Hudson River Trading (medium)
  • Test easy–medium array/string tasks - Hudson River Trading (Medium)
  • Approach verbose data-structure design - Hudson River Trading (Medium)