Array Hash Table 3162. Find the Number of Good Pairs I ¶ Time: $O(nm)$ Space: $O(1)$ C++JavaPython 1 2 3 4 5 6 7 8 9 10 11class Solution { public: int numberOfPairs(vector<int>& nums1, vector<int>& nums2, int k) { int ans = 0; for (const int num1 : nums1) for (const int num2 : nums2) if (num1 % (num2 * k) == 0) ++ans; return ans; } }; 1 2 3 4 5 6 7 8 9 10class Solution { public int numberOfPairs(int[] nums1, int[] nums2, int k) { int ans = 0; for (final int num1 : nums1) for (final int num2 : nums2) if (num1 % (num2 * k) == 0) ++ans; return ans; } } 1 2 3 4 5class Solution: def numberOfPairs(self, nums1: list[int], nums2: list[int], k: int) -> int: return sum(num1 % (num2 * k) == 0 for num1 in nums1 for num2 in nums2)