Back to problems

Continuous Subarray Sum

Algorithm · Meta · Medium

You are given an integer array nums and an integer k. Implement the function checkSubarraySum(nums, k), which returns True exactly when some contiguous subarray of nums containing at least two elements adds up to a multiple of k. Whenever k is nonzero, the matching multiple must itself be nonzero; when k equals 0, the only multiple is 0, so the selected subarray's sum must be 0. Return False if no contiguous subarray of length two or greater satisfies this condition.…

Checking your access…