Search topics...
All Problems

Continuous Subarray Sum

Solution Approach
Was this helpful?
MediumarrayExpected: O(n) time, O(n) space
hash-mapprefix-sum

Problem

Given an integer array and an integer k, return true if the array has a continuous subarray of size at least two whose elements sum up to a multiple of k.

Example 1:

Input: nums = [23, 2, 4, 6, 7], k = 6
Output: true
Explanation: [2, 4] sums to 6, which is a multiple of 6.

Example 2:

Input: nums = [23, 2, 6, 4, 7], k = 13
Output: false
Reference solution unlocks after your first submission
Loading...