Tap here to switch tabs
Problem
Submissions

Problem: Count Almost Equal Pairs I

med
30 min
Try to solve the Count Almost Equal Pairs I problem.

Statement

You are given an array nums consisting of positive integers.

Two integers xx and yy are considered almost equal if it is possible to make them equal by swapping at most one pair of digits in at most one of the numbers. Swapping can be performed after optionally appending leading zeros to the number with fewer digits so that both numbers have the same number of digits.

Return the total number of index pairs (i,j)(i, j) such that 0≤i<j<0 \leq i < j < nums.length where nums[i] and nums[j] are almost equal.

Constraints:

  • 2≤2 \leq nums.length ≤100\leq 100

  • 1≤1 \leq nums[i] ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Almost Equal Pairs I

med
30 min
Try to solve the Count Almost Equal Pairs I problem.

Statement

You are given an array nums consisting of positive integers.

Two integers xx and yy are considered almost equal if it is possible to make them equal by swapping at most one pair of digits in at most one of the numbers. Swapping can be performed after optionally appending leading zeros to the number with fewer digits so that both numbers have the same number of digits.

Return the total number of index pairs (i,j)(i, j) such that 0≤i<j<0 \leq i < j < nums.length where nums[i] and nums[j] are almost equal.

Constraints:

  • 2≤2 \leq nums.length ≤100\leq 100

  • 1≤1 \leq nums[i] ≤106\leq 10^6