#3162
Easy Algorithms Find the number of good pairs i
Array Hash Table
86.3% acceptance
Feb 24, 2026
164
16
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.
Return the total number of good pairs.
Solution
Rust
Time O(n²)
Space O(1)
impl Solution {
pub fn number_of_pairs(nums1: Vec<i32>, nums2: Vec<i32>, k: i32) -> i32 {
let mut count = 0;
for &a in &nums1 {
for &b in &nums2 {
if a % (b * k) == 0 {
count += 1;
}
}
}
count
}
}