 All Problems
Continuous Subarray Sum
medium
prefix sum
hash map
math
facebook
amazon
google

Given an integer array nums and an integer k, return true if nums has a continuous subarray of size at least 2 whose elements sum up to a multiple of k, or false otherwise.

Example 1:

Input: 23 2 4 6 7
k: 6
Output: true
Explanation: [2,4] has sum 6 = 1*6.

Example 2:

Input: 23 2 6 4 7
k: 6
Output: true
Explanation: [23,2,6,4,7] has sum 42 = 7*6.

Constraints:

  • 1 ≤ nums.length ≤ 10⁵
  • 0 ≤ nums[i] ≤ 10⁹
  • 0 ≤ k ≤ 2³¹ - 1

Input format: First line: space-separated array. Second line: k.

Output format: true or false.

Run to check your code against the sample cases, or submit to run every case