File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 196419642640|[ Find the Score of All Prefixes of an Array] ( ./solutions/2640-find-the-score-of-all-prefixes-of-an-array.js ) |Medium|
196519652641|[ Cousins in Binary Tree II] ( ./solutions/2641-cousins-in-binary-tree-ii.js ) |Medium|
196619662643|[ Row With Maximum Ones] ( ./solutions/2643-row-with-maximum-ones.js ) |Easy|
1967+ 2644|[ Find the Maximum Divisibility Score] ( ./solutions/2644-find-the-maximum-divisibility-score.js ) |Easy|
196719682648|[ Generate Fibonacci Sequence] ( ./solutions/2648-generate-fibonacci-sequence.js ) |Easy|
196819692649|[ Nested Array Generator] ( ./solutions/2649-nested-array-generator.js ) |Medium|
196919702650|[ Design Cancellable Function] ( ./solutions/2650-design-cancellable-function.js ) |Hard|
Original file line number Diff line number Diff line change 1+ /**
2+ * 2644. Find the Maximum Divisibility Score
3+ * https://leetcode.com/problems/find-the-maximum-divisibility-score/
4+ * Difficulty: Easy
5+ *
6+ * You are given two integer arrays nums and divisors.
7+ *
8+ * The divisibility score of divisors[i] is the number of indices j such that nums[j] is
9+ * divisible by divisors[i].
10+ *
11+ * Return the integer divisors[i] with the maximum divisibility score. If multiple integers
12+ * have the maximum score, return the smallest one.
13+ */
14+
15+ /**
16+ * @param {number[] } nums
17+ * @param {number[] } divisors
18+ * @return {number }
19+ */
20+ var maxDivScore = function ( nums , divisors ) {
21+ let maxScore = 0 ;
22+ let result = divisors [ 0 ] ;
23+
24+ for ( const divisor of divisors ) {
25+ let score = 0 ;
26+ for ( const num of nums ) {
27+ if ( num % divisor === 0 ) {
28+ score ++ ;
29+ }
30+ }
31+ if ( score > maxScore || ( score === maxScore && divisor < result ) ) {
32+ maxScore = score ;
33+ result = divisor ;
34+ }
35+ }
36+
37+ return result ;
38+ } ;
You can’t perform that action at this time.
0 commit comments