Skip to content

Practice Count Almost Equal Pairs II

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#3267
LeetCode Problem

Count Almost Equal Pairs II

Problem Statement

Two positive integers are almost equal when they can be made equal using at most two digit swaps in total. Each swap exchanges any two digits within either chosen integer. Leading zeroes produced by a swap are allowed. Count pairs of indices i < j in nums whose values are almost equal.

Source: Count Almost Equal Pairs II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1023,2310,2130,213]
Output
4

# Example 2

Input
nums = [1,10,100]
Output
3

Constraints

2 <= nums.length <= 5000
1 <= nums[i] < 10^7

Related LeetCode Problems

Practice more problems similar to Count Almost Equal Pairs II.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.