Continuous Subarray Sum (Multiple of k)

Given an integer array *nums* and an integer *k*, return `true` if there exists a continuous subarray of size at least two whose sum is a multiple of *k* (i.e., sum = n*k for some integer n). Otherwise, return `false`.

Input Format

nums = [array of nonnegative integers], k = integer

Output Format

boolean (true/false)

Constraints

  • 1 <= nums.length <= 10^4; 0 <= nums[i] <= 10^9; 1 <= k <= 10^9

Examples

Example 1:

Input:

nums = [23,2,4,6,7]
k = 6

Output:

true

Explanation:

Subarray [2,4] sums to 6, which is a multiple of 6.

Example 2:

Input:

nums = [23,2,6,4,7]
k = 6

Output:

true

Explanation:

Subarray [23,2,6,4,7] sums to 42, which is 7 * 6.

Example 3:

Input:

nums = [23,2,6,4,7]
k = 13

Output:

false

Explanation:

No subarray of length >=2 sums to a multiple of 13.

Loading...
Continuous Subarray Sum (Multiple of k)