Detect a Length-Two-or-More Multiple-Sum Segment. Return whether nums contains a contiguous subarray of at least two elements whose sum is an integer multiple of positive k.
### Problem
Return whether nums contains a contiguous subarray of at least two elements whose sum is an integer multiple of positive k. Zero is a multiple of every allowed k.
```cpp
class Solution {
public:
bool checkSubarraySum(vector<int>& nums, int k);
};
```
### Examples
**Example 1:**
```text
nums = [5,1,2], k = 3
Output: true
Explanation: The last two elements sum to 3.
```
**Example 2:**
```text
nums = [1,2], k = 4
Output: false
Explanation: The only eligible subarray sums to 3.
```
### Constraints
- Input size: 1..100000. Individual values: 0..1000000000. Their total is between 0 and 2147483647. The modulus k is in 1..2147483647.
### Clarifying Questions
Enforce the minimum length and preserve the earliest occurrence of each remainder.
```hint Read the boundary condition
When do two prefix sums differ by a multiple of k?
```
### Contract considerations
Enforce the minimum length and preserve the earliest occurrence of each remainder.
Overview: Detect a Length-Two-or-More Multiple-Sum Segment. Return whether nums contains a contiguous subarray of at least two elements whose sum is an integer multiple of positive k.
Return whether nums contains a contiguous subarray of at least two elements whose sum is an integer multiple of positive k. Zero is a multiple of every allowed k.
class Solution {
public:
bool checkSubarraySum(vector<int>& nums, int k);
};
Examples
Example 1:
nums = [5,1,2], k = 3
Output: true
Explanation: The last two elements sum to 3.
Example 2:
nums = [1,2], k = 4
Output: false
Explanation: The only eligible subarray sums to 3.
Constraints
Input size: 1..100000. Individual values: 0..1000000000. Their total is between 0 and 2147483647. The modulus k is in 1..2147483647.
Clarifying Questions Guidance
Enforce the minimum length and preserve the earliest occurrence of each remainder.
Contract considerations
Enforce the minimum length and preserve the earliest occurrence of each remainder.