Problem Brief
Count Distinct Pairs
INTERNOA
There is an array of fruits. Your goal is to calculate the amount of distinct pairs (x, y) so that
0 <= x < y < length of fruits. Note that fruits[x] could be gotten from fruits[y] by swapping no more than
2 digits of fruits[y] :)
Note again:: One might not make swapping to any digits at all, so, if x < y and fruits[x] = fruits[y], such pair
should be counted.
1Example 1
Input
fruits = [1, 23, 156, 1650, 651, 165, 32]
Output
3
Explanation
- fruist[1] = 23 could be gotten from fruits[6] = 32 just by swapping its only 2 digits :)
- fruist[2] = 156 could be gotten from fruits[4] = 651 just by swapping six and one :))
- fruist[2] = 156 could be gotten from fruits[5] = 165 just by swapping six & five :))
2Example 2
Input
fruits = [123, 321, 123]
Output
3
Explanation
- fruits[1] = 321 could be gotten from fruits[0] = 123, swapping one & three
- fruits[2] = 123 could be gotten from fruits[0] = 123, swapping nothing
- fruits[2] = 123 could be gotten from fruits[1] = 321, swapping three & one
Constraints
Limits and guarantees your solution can rely on.
1 <= fruits.length <= 1041 <= numbers[i] <= 109