Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Compute the prefix sum array where psum[i] is the sum of all the elements from <i>0</i> to <i>i</i>.
At each index <i>i</i>, the sum of the prefix is psum[i], so we are searching for the index x where psum[x] = psum[i] - k. The subarray [x + 1, i] will be of sum k.
Use a hashmap to get the index x efficiently or to determine that it does not exist.