Skip to content

Practice Minimum Operations to Make Array Sum Divisible by K

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#3512
LeetCode Problem

Minimum Operations to Make Array Sum Divisible by K

Problem Statement

Given nums and k, one operation decreases any chosen element by 1. Return the minimum number of operations needed to make the sum of nums divisible by k.

Source: Minimum Operations to Make Array Sum Divisible by K on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [3,9,7], k = 5
Output
4

# Example 2

Input
nums = [4,1,3], k = 4
Output
0

# Example 3

Input
nums = [3,2], k = 6
Output
5

Constraints

1 <= nums.length <= 1000
1 <= nums[i] <= 1000
1 <= k <= 100

Related LeetCode Problems

Practice more problems similar to Minimum Operations to Make Array Sum Divisible by K.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.