FastPrepCount Pairs Differing in One Digit

Count Pairs Differing in One Digit

ZipRecruiter logoZipRecruiter● EasyNEW GRADOA
Learn

Problem statement

Given positive integers numbers, count index pairs i < j whose ordinary decimal representations have equal length and differ at exactly one aligned digit position.

Function

countOneDigitDifferencePairs(numbers: int[]) → long

Examples

Example 1

numbers = [12,13,22,12]return = 4

The qualifying index pairs are the first 12 with 13 and 22, 13 with the final 12, and 22 with the final 12.

Example 2

numbers = [1,2,3]return = 3

Every pair differs at its only digit.

Constraints

  • 0 <= numbers.length <= 2000
  • 1 <= numbers[i] <= 1000000000

More ZipRecruiter problems

See ZipRecruiter hiring insights
public long countOneDigitDifferencePairs(int[] numbers) {
    // Write your code here.
}
numbers[12,13,22,12]
expected4
Checking account…