Count Almost Equal Pairs I

You are given an array nums consisting of positive integers.

We call two integers x and y in this problem almost equal if both integers can become equal after performing the following operation at most once:

  • Choose either x or y and swap any two digits within the chosen number.

Return the number of indices i and j in nums where i < j such that nums[i] and nums[j] are almost equal.

Note that it is allowed for an integer to have leading zeros after performing an operation.

Example 1
Inputnums = [3,12,30,17,21]
Output2
The almost equal pairs are 3 and 30, and 12 and 21.
Example 2
Inputnums = [1,1,1,1,1]
Output10
Every two elements in the array are almost equal.

Constraints

  • 2 <= nums.length <= 100
  • 1 <= nums[i] <= 10^6

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate