Continuous Subarray Sum
Given an integer array nums and an integer k, return true if nums has a continuous subarray of length at least 2 whose elements sum to a multiple of k (that is, the sum equals n*k for some integer n, including 0). Otherwise return false.
Open official problem prompt ↗Decide whether some window of at least two consecutive elements sums to a multiple of k.
Picture a clock with k hours. Each element advances the hand. If the hand returns to a position it held before, the elapsed hours between those moments is a whole number of full laps, that is, a multiple of k.
- Input
- nums = [23, 2, 4, 6, 7], k = 6
- Output
- true
- Why
- The subarray [2, 4] has length 2 and sums to 6, which is 1 * 6
1 <= nums.length <= 10^50 <= nums[i] <= 10^90 <= sum(nums) <= 2^31 - 11 <= k <= 2^31 - 1