Q3 Find the Number of Good Pairs II
class Solution {
public:
long long numberOfPairs(vector<int>& nums1, vector<int>& nums2, int k) {
long long res = 0;
int mx = *max_element(nums1.begin(),nums1.end());
map<int,int> mp1,mp2;
for(int x : nums1){
mp1[x]++;
}
for(int x : nums2){
mp2[x]++;
}
for(auto it : mp2){
int temp = it.first * k;
for(int i = temp;i <= mx;i += temp){
if(mp1.find(i) != mp1.end()){
res += (long long)it.second * (long long)mp1[i];
}
}
}
return res;
}
};