Sum of Digit Differences of All Pairs
You are given an array nums consisting of positive integers where all integers have the same number of digits.
The digit difference between two integers is the count of different digits that are in the same position in the two integers.
Return the sum of the digit differences between all pairs of integers in nums.
Example 1
Input
nums = [13,23,12]Output
4The pairwise digit differences are 1 for 13 and 23, 1 for 13 and 12, and 2 for 23 and 12, for a total of 4.
Example 2
Input
nums = [10,10,10,10]Output
0All the integers in the array are the same, so every pair has digit difference 0.
Constraints
- 2 <= nums.length <= 10^5
- 1 <= nums[i] < 10^9
- All integers in nums have the same number of digits.