# Need help to understand logic in the code

The below code is returning the total number of subarrays whose sum equals to k. I am trying to understand logic in the below code: nums = [1,3,1] k = 4 dic = {0:1} res = 0 curr = 0 for i in range(len(nums)): curr += nums[i] res += dic.get(curr-k, 0) #need help to understand… Read More Need help to understand logic in the code