Attention: In this version, the number of operations that can be performed, has been increased to twice.
You are given an array nums consisting of positive integers.
We call two integers x and y almost equal if both integers can become equal after performing the following operation at most twice:
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:
Input: nums = [1023,2310,2130,213]
Output: 4
Explanation:
The almost equal pairs of elements are:
Example 2:
Input: nums = [1,10,100]
Output: 3
Explanation:
The almost equal pairs of elements are:
Constraints:
2 <= nums.length <= 50001 <= nums[i] < 107Solutions for this problem are being prepared.
Try solving it yourselfCount the Number of Fair Pairs - Leetcode 2563 - Python • NeetCodeIO • 15,313 views views
Watch 9 more video solutions →Practice Count Almost Equal Pairs II with our built-in code editor and test cases.
Practice on FleetCodePractice this problem
Open in Editor