Skip to content

Commit 3430ee4

Browse files
committed
Add solution #2644
1 parent 8612063 commit 3430ee4

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,6 +1964,7 @@
19641964
2640|[Find the Score of All Prefixes of an Array](./solutions/2640-find-the-score-of-all-prefixes-of-an-array.js)|Medium|
19651965
2641|[Cousins in Binary Tree II](./solutions/2641-cousins-in-binary-tree-ii.js)|Medium|
19661966
2643|[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|
19671968
2648|[Generate Fibonacci Sequence](./solutions/2648-generate-fibonacci-sequence.js)|Easy|
19681969
2649|[Nested Array Generator](./solutions/2649-nested-array-generator.js)|Medium|
19691970
2650|[Design Cancellable Function](./solutions/2650-design-cancellable-function.js)|Hard|
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
};

0 commit comments

Comments
 (0)