1814. Count Nice Pairs in an Array
- store the diff b/w new and old nos.
nCr
it.
Implementation
```cpp
using ll = long long int;
const int mod = int(1e9 + 7);
class Solution {
public:
int rev(int n){
int revNum = 0;
while(n) revNum = revNum * 10 + (n % 10), n /= 10;
return revNum;
}
int countNicePairs(vector& nums) {
ll count = 0;
map<int, ll> mp;
for(const auto& num : nums) mp[num - rev(num)]++;
for(const auto& pair : mp)
count = (count + (pair.second * (pair.second - 1)) / 2) % mod;
return count;
}
};
```
</details>