This question contains two part:
- Count the number of subarrays (continuous) whose sum equal to the given k.
- In all subarrays found above, find as many non-overlapping subarrays as possible that gives the maximal total sum. Output the total sum.
Q1 is Leetcode 560.
Q2 is new. Example:
[1,1,1], k = 2, there are 2 subarrays whose sum is 2, but they are overlapping.
So for Q2, output 2 instead of 4.