Class Solution
java.lang.Object
g2301_2400.s2344_minimum_deletions_to_make_array_divisible.Solution
2344 - Minimum Deletions to Make Array Divisible.<p>Hard</p>
<p>You are given two positive integer arrays <code>nums</code> and <code>numsDivide</code>. You can delete any number of elements from <code>nums</code>.</p>
<p>Return <em>the <strong>minimum</strong> number of deletions such that the <strong>smallest</strong> element in</em> <code>nums</code> <em><strong>divides</strong> all the elements of</em> <code>numsDivide</code>. If this is not possible, return <code>-1</code>.</p>
<p>Note that an integer <code>x</code> divides <code>y</code> if <code>y % x == 0</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [2,3,2,4,3], numsDivide = [9,6,9,3,15]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong></p>
<p>The smallest element in [2,3,2,4,3] is 2, which does not divide all the elements of numsDivide.</p>
<p>We use 2 deletions to delete the elements in nums that are equal to 2 which makes nums = [3,4,3].</p>
<p>The smallest element in [3,4,3] is 3, which divides all the elements of numsDivide.</p>
<p>It can be shown that 2 is the minimum number of deletions needed.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [4,3,6], numsDivide = [8,2,6,10]</p>
<p><strong>Output:</strong> -1</p>
<p><strong>Explanation:</strong></p>
<p>We want the smallest element in nums to divide all the elements of numsDivide.</p>
<p>There is no way to delete elements from nums to allow this.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length, numsDivide.length <= 10<sup>5</sup></code></li>
<li><code>1 <= nums[i], numsDivide[i] <= 10<sup>9</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minOperations
public int minOperations(int[] nums, int[] numsDivide)
-