File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 212721272341|[ Maximum Number of Pairs in Array] ( ./solutions/2341-maximum-number-of-pairs-in-array.js ) |Easy|
212821282342|[ Max Sum of a Pair With Equal Sum of Digits] ( ./solutions/2342-max-sum-of-a-pair-with-equal-sum-of-digits.js ) |Medium|
212921292343|[ Query Kth Smallest Trimmed Number] ( ./solutions/2343-query-kth-smallest-trimmed-number.js ) |Medium|
2130+ 2344|[ Minimum Deletions to Make Array Divisible] ( ./solutions/2344-minimum-deletions-to-make-array-divisible.js ) |Hard|
213021312345|[ Finding the Number of Visible Mountains] ( ./solutions/2345-finding-the-number-of-visible-mountains.js ) |Medium|
213121322347|[ Best Poker Hand] ( ./solutions/2347-best-poker-hand.js ) |Easy|
213221332348|[ Number of Zero-Filled Subarrays] ( ./solutions/2348-number-of-zero-filled-subarrays.js ) |Medium|
Original file line number Diff line number Diff line change 1+ /**
2+ * 2344. Minimum Deletions to Make Array Divisible
3+ * https://leetcode.com/problems/minimum-deletions-to-make-array-divisible/
4+ * Difficulty: Hard
5+ *
6+ * You are given two positive integer arrays nums and numsDivide. You can delete any number
7+ * of elements from nums.
8+ *
9+ * Return the minimum number of deletions such that the smallest element in nums divides
10+ * all the elements of numsDivide. If this is not possible, return -1.
11+ *
12+ * Note that an integer x divides y if y % x == 0.
13+ */
14+
15+ /**
16+ * @param {number[] } nums
17+ * @param {number[] } numsDivide
18+ * @return {number }
19+ */
20+ var minOperations = function ( nums , numsDivide ) {
21+ const targetGcd = numsDivide . reduce ( gcd ) ;
22+ nums . sort ( ( a , b ) => a - b ) ;
23+
24+ for ( let i = 0 ; i < nums . length ; i ++ ) {
25+ if ( targetGcd % nums [ i ] === 0 ) {
26+ return i ;
27+ }
28+ }
29+
30+ return - 1 ;
31+
32+ function gcd ( a , b ) {
33+ return b === 0 ? a : gcd ( b , a % b ) ;
34+ }
35+ } ;
You can’t perform that action at this time.
0 commit comments