v9.1.1
Menu

Continuous Subarray Sum

mediumFREEArrays & HashingNetflix DSA

Given an integer array nums and an integer k, return True if nums has a subarray of size at least two whose elements sum to a multiple of k.

Example

Input
23,2,4,6,7
6
Output
True
Reasoning
  • The input array is [23, 2, 4, 6, 7] and k is 6.
  • We examine all possible subarrays of size at least two to find one whose sum is a multiple of k=6k = 6.
  • One such subarray is [2, 4], with a sum of 2+4=62 + 4 = 6, which is a multiple of 66: 6=6⋅16 = 6 \cdot 1.
  • Since we found a subarray whose sum is a multiple of kk, the function returns True.

Constraints

  • 1 <= len(nums) <= 10^5
  • 0 <= nums[i] <= 10^9
  • 0 <= k <= 2^31 - 1

Learn this in

More from Netflix DSA

solution.py

Test results

Sign in to run your code against the test cases.