Problem Description
You are given two integer arrays nums1 and nums2 along with a positive integer k. A pair (i, j) is called good if nums1[i] is divisible by (nums2[j] * k). Your task is to count and return the number of good pairs.
Key Insights
- Since the input sizes are relatively small (each array can have at most 50 elements), a brute-force approach is acceptable.
- Use nested loops to iterate through every pair of elements from nums1 and nums2.
- Check whether nums1[i] is divisible by (nums2[j] * k).
Space and Time Complexity
Time Complexity: O(n * m), where n = length of nums1 and m = length of nums2.
Space Complexity: O(1)
Solution
We utilize two nested loops to traverse every combination of elements from nums1 and nums2. For each pair, check if the element from nums1 is divisible by the product of the corresponding element from nums2 and k. If the condition is met, increment a counter. Finally, return the counter as the total number of good pairs.