I think there is one more case which should be included in the code

let us suppose k=3. and we have Current sum=6 and sum 3 is already present in the map. So we have found the sub- array with K sum. Here we have to check again if Curr some which is 6 is present or not in the map. If we don’t check this then there would be a problem when we have a current sum of 9.
Correct me if i’m wrong :wink:

2 things are to be noticed here.
First is that sum will never decrease since we are dealing with positive numbers only.
Second … after the first point is clear you can store the first occurance only like if the array was 6 0 0 0 0 .
And now the prefix sum would be 6 6 6 6 6 . so just store the first index where 6 occured that would give us the correct answer.