PIXELBANKv9.1.0
Menu

Continuous Subarray Sum

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
solution.py

Test Results

0/0
Run code to see test results.
Continuous Subarray Sum - Medium | PixelBank