Subarray Sum Equals K




@FF_TI No need of put(0,1):
public int subarraySum(int[] nums, int k) { int count=0,sum=0; Map<Integer,Integer> hm = new HashMap<>(); for(int i=0;i<nums.length;i++){ hm.put(sum, hm.getOrDefault(sum,0)+1); sum+=nums[i]; count+=hm.getOrDefault((sumk),0); } return count; }

I am not sure I understood the first paragraph of the third solution correctly.
Suppose you have "1, 2, 3, 4, 5" > [ sum[0]=1, sum[1]=3, sum[2]=6, sum[3]=10, sum[4]=15]
According to your saying "if the cumulative sum upto two indices, say i and j is at a difference of k i.e. if sum[i]  sum[j] = k, the sum of elements lying between indices i and j is k."
so sum[3]  sum[1] = 10  3 = 7, which means the sum of elements lying between indices 3 and 1 is 7? what do you mean the sum of elements?