FastPrepCount Distinct Pairs
Problems/Count Distinct Pairs

Count Distinct Pairs

Databricks logoDatabricks● MediumINTERNOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: 🐣 2026-07-18. This problem is backed by a real source. The judged core task matches the source at about 95%. The source presents this as a Google onsite question, so this version does not present it as a Databricks attribution.

Given an array of positive integers fruits, count the index pairs (x, y) such that 0 <= x < y < fruits.length and fruits[x] can be obtained from fruits[y] by swapping at most one pair of decimal digit positions. Making no swap is allowed, so equal values form a valid pair.

Function

ddCountPairs(fruits: int[]) → int

Examples

Example 1

fruits = [1, 23, 156, 4738, 321, 72992, 231, 651, 32]return = 3

The valid pairs are 23 with 32, 156 with 651, and 321 with 231. Each later value becomes the earlier value after one digit-position swap.

Constraints

  • 1 <= fruits.length <= 10000
  • 1 <= fruits[i] <= 1000000000
  • The answer fits a 32-bit signed integer.

More Databricks problems

  • Rolling Hit CounterPHONE SCREEN · Seen Nov 2026
  • Minimize CommuteOA · PHONE SCREEN · Seen Oct 2026
  • Path Between Two Nodes of a Fibonacci TreeONSITE INTERVIEW · Seen Oct 2026
All Databricks interview questionsSee Databricks hiring insights
Saved
class Solution {
    public int ddCountPairs(int[] fruits) {
        // write your code here
    }

}
Checking account…