Count Distinct Swappable Digit Pairs

Asked at ZipRecruiter · Coding Questions · Difficulty: Medium

Given an array `numbers`, count how many distinct pairs of indexes `(i, j)` with `0 <= i < j < numbers.length` satisfy: the number at position `j` can be transformed into the number at position `i` by swapping **at most two** of its digits. Note: sometimes no swapping is needed at all — if the two numbers are already the same, they still count as a valid pair.

Loading the problem…