ZipRecruiterOA #4
Count Distinct Swappable Digit Pairs
估计中等可在线判题
For each i<j, the pair is valid if the decimal representation of numbers[j] can become numbers[i] with at most one swap (swapping one pair of positions); no swap is also allowed. Only numbers with the same number of digits are counted. Find the number of pairs. A swap must not create a leading zero.
输入格式
The first line contains n (1..100000), and the second line contains n integers (0..10^9) in ordinary decimal representation.
输出格式
Output the number of valid pairs; the result may exceed 32 bits.
样例 1
输入:
4
12 21 12 123
输出:
3
样例 2
输入:
2
7 7
输出:
1
样例 3
输入:
4
1 10 100 1000
输出:
0