2344. Minimum Deletions to Make Array Divisible Hard
1/**
2 * [2344] Minimum Deletions to Make Array Divisible
3 *
4 * You are given two positive integer arrays nums and numsDivide. You can delete any number of elements from nums.
5 * Return the minimum number of deletions such that the smallest element in nums divides all the elements of numsDivide. If this is not possible, return -1.
6 * Note that an integer x divides y if y % x == 0.
7 *
8 * Example 1:
9 *
10 * Input: nums = [2,3,2,4,3], numsDivide = [9,6,9,3,15]
11 * Output: 2
12 * Explanation:
13 * The smallest element in [2,3,2,4,3] is 2, which does not divide all the elements of numsDivide.
14 * We use 2 deletions to delete the elements in nums that are equal to 2 which makes nums = [3,4,3].
15 * The smallest element in [3,4,3] is 3, which divides all the elements of numsDivide.
16 * It can be shown that 2 is the minimum number of deletions needed.
17 *
18 * Example 2:
19 *
20 * Input: nums = [4,3,6], numsDivide = [8,2,6,10]
21 * Output: -1
22 * Explanation:
23 * We want the smallest element in nums to divide all the elements of numsDivide.
24 * There is no way to delete elements from nums to allow this.
25 *
26 * Constraints:
27 *
28 * 1 <= nums.length, numsDivide.length <= 10^5
29 * 1 <= nums[i], numsDivide[i] <= 10^9
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/minimum-deletions-to-make-array-divisible/
35// discuss: https://leetcode.com/problems/minimum-deletions-to-make-array-divisible/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn min_operations(nums: Vec<i32>, nums_divide: Vec<i32>) -> i32 {
41 0
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_2344() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.