Skip to content

Commit 0fa2893

Browse files
committed
Add solution #3512
1 parent 4261a9d commit 0fa2893

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2778,6 +2778,7 @@
27782778
3506|[Find Time Required to Eliminate Bacterial Strains](./solutions/3506-find-time-required-to-eliminate-bacterial-strains.js)|Hard|
27792779
3508|[Implement Router](./solutions/3508-implement-router.js)|Medium|
27802780
3511|[Make a Positive Array](./solutions/3511-make-a-positive-array.js)|Medium|
2781+
3512|[Minimum Operations to Make Array Sum Divisible by K](./solutions/3512-minimum-operations-to-make-array-sum-divisible-by-k.js)|Easy|
27812782
3516|[Find Closest Person](./solutions/3516-find-closest-person.js)|Easy|
27822783
3520|[Minimum Threshold for Inversion Pairs Count](./solutions/3520-minimum-threshold-for-inversion-pairs-count.js)|Medium|
27832784
3535|[Unit Conversion II](./solutions/3535-unit-conversion-ii.js)|Medium|
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* 3512. Minimum Operations to Make Array Sum Divisible by K
3+
* https://leetcode.com/problems/minimum-operations-to-make-array-sum-divisible-by-k/
4+
* Difficulty: Easy
5+
*
6+
* You are given an integer array nums and an integer k. You can perform the following
7+
* operation any number of times:
8+
* - Select an index i and replace nums[i] with nums[i] - 1.
9+
*
10+
* Return the minimum number of operations required to make the sum of the array
11+
* divisible by k.
12+
*/
13+
14+
/**
15+
* @param {number[]} nums
16+
* @param {number} k
17+
* @return {number}
18+
*/
19+
var minOperations = function(nums, k) {
20+
return nums.reduce((sum, n) => sum + n, 0) % k;
21+
};

0 commit comments

Comments
 (0)