values. Call two numbers twins if they can be made equal with at most one operation: pick one of the two numbers and swap any two digits in it.
Leading zeros are fine after a swap: for example, 50 can become 05, which is just 5.
Return the number of index pairs i < j such that values[i] and values[j] are twins. Equal numbers are twins too; they need no swap at all.values=[13, 31, 130, 5] → 2
13 and 31: swap the digits of 13. 31 and 130: swap the 1 and the 0 in 130 to get 031, which is 31. No other pair works.
values=[7, 7, 70] → 3
The two 7s are already equal, and 70 becomes 07 = 7 after one swap. All three pairs count.
values=[123, 312] → 0
All three positions differ, which a single swap cannot fix.
values=[13, 31, 130, 5]
2
Run checks the first 3 tests in your browser. Submit checks all 116 tests on the server, hidden ones included.