LeetCode Problem - Link
Problem
You are given 2 integer arrays nums1 and nums2 of lengths n and m respectively. You are also given a positive integer k.
A pair (i, j) is called good if nums1[i] is divisible by nums2[j] * k (0 <= i <= n - 1, 0 <= j <= m - 1).
Return the total number of good pairs.
Example 1:
Input: nums1 = [1,3,4], nums2 = [1,3,4], k = 1
Output: 5
Explanation:
The 5 good pairs are (0, 0), (1, 0), (1, 1), (2, 0), and (2, 2).
Sequential Approach
You can easily get this wrong if you don't include or consider brackets, thanks to my LeetCode buddy Ravi for pointing this out. I probably wouldn't figure it out.
/** * @param {number[]} nums1 * @param {number[]} nums2 * @param {number} k * @return {number} */ var numberOfPairs = function (nums1, nums2, k) { var count = 0; for (var i = 0; i < nums1.length; i++) { for (var j = 0; j < nums2.length; j++) { // Note BO-DMAS if (nums1[i] % (nums2[j] * k) === 0) { count += 1 } } } return count };