Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Save all the prefix sums into a HashMap.
For the index <code>i</code> store the element at index <code>i + 1</code> as the key and the prefix sum till <code>i</code> as the value.
For each prefix sum ending at <code>nums[i]</code>, try finding <code>nums[i] - k</code> and <code>nums[i] + k</code> in the HashMap and update the answer.