Back to DSA sheet

Continuous Subarray Sum

MediumArrays

Decide whether the array has a contiguous subarray of length at least two whose sum is a multiple of k (including 0).

Input format (stdin): the first line has n and k. The second line has n integers. Output true or false.

Examples
Input: 5 6 23 2 4 6 7
Output: true
[2,4] sums to 6, a multiple of 6.
Input: 5 13 23 2 6 4 7
Output: false
No length-2+ subarray sums to a multiple of 13.
Constraints
  • 1 <= n <= 10^5
  • 1 <= k <= 2^31 - 1
  • 0 <= nums[i] <= 10^9
Sheets
NeetCode 250
continuous-subarray-sum.cpp3 sample tests
Loading editor
Test results

Run the sample tests to check your solution against expected output.

Custom input (stdin)
Output

Run your code to see its output.