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
Inputnums = [13,23,12]
Output4
The 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
Inputnums = [10,10,10,10]
Output0
All 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.

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate