Count Pairs Differing in One Digit
Updated
Problem statement
You are given an array of positive integers numbers. Count pairs of indices i < j where the two numbers have the same number of decimal digits and differ at exactly one digit position.
For this exercise, assume decimal representations have no leading zeros. Different occurrences of an equal value are different array elements, but two equal values differ at zero positions and therefore do not form a qualifying pair.
Return the number of qualifying index pairs as a signed 64-bit integer.
Function
countOneDigitDifferencePairs(numbers: int[]) → longExamples
Example 1
numbers = [12,13,22,12]return = 4The qualifying pairs connect either occurrence of 12 with 13 or 22. The equal values do not qualify.
Example 2
numbers = [1,2,10,20]return = 2The pairs are 1 with 2 and 10 with 20. Different decimal lengths are not compared.
Example 3
numbers = [111,121,131,222]return = 3The first three values differ only at their middle digit, producing three pairs. 222 differs at more than one position from each.
Constraints
0 <= numbers.length <= 100000.1 <= numbers[i] <= 10^9.
More Roblox Online Assessment questions
- Centered Block Placement QueriesOA · Seen Oct 2026
- Robot Navigation Around LasersOA · Seen Oct 2026
- Factory Batch Profit (Game Adaptation)OA · Seen Sep 2026
- Nested Recipe Blocks (Game Adaptation)OA · Seen Sep 2026
- Vehicle Builds for Required Terrain (Game Adaptation)OA · Seen Sep 2026
- Track Received Byte RangesOA · Seen Sep 2026
- Inventory Discount TrackerOA · Seen Sep 2026
- Break a PalindromeOA · Seen Jun 2026
- Find Zero Cells in a 2×2 GridOA · Seen Oct 2025
- Cat Route Budget Planning (Game Adaptation)OA · Seen Aug 2025
Similar questions at other companies
- Count Suffix Word PairsTikTok · OA
- Count One-Swap Number PairsCapital One · OA
- Maximum Equal Parts for PrefixesAmazon · OA
- Cheating CodemakerJane Street · OA
- Candidate Alias Name MatchingCheckr · OA · PHONE SCREEN
- Aggregate Paginated Project Run RecordsReplit · OA
- Maximum Common Decimal Prefix Across ArraysZipRecruiter · OA
- Count User Mentions in Chat MessagesRamp · OA
- Find Words That Can Be Formed by CharactersTabaPay · OA
- Word Frequency Counts in Alphabetical OrderAbridge · OA