Count Pairs Differing in One Digit
Problem statement
Given positive integers numbers, count index pairs i < j whose ordinary decimal representations have equal length and differ at exactly one aligned digit position.
Function
countOneDigitDifferencePairs(numbers: int[]) → longExamples
Example 1
numbers = [12,13,22,12]return = 4The qualifying index pairs are the first 12 with 13 and 22, 13 with the final 12, and 22 with the final 12.
Example 2
numbers = [1,2,3]return = 3Every pair differs at its only digit.
Constraints
0 <= numbers.length <= 20001 <= numbers[i] <= 1000000000