Mistake in function

plz check for this input

11
1 4 0 4 0 0 0 0 0 -1 1
4

where n=11;
next 11 input are array intergers and k=4;

my doubt is if we get mp[pre-k] then we skip entering mp[pre] in the map .then next time if we get new pre for which last pre can be pre-k for this pre.then then we could not get the answer.
for more clarification reger to input example i given

yes i think instead of that else
condition we should check if mp[pre] == mp.end()
then mp[pre] = i;

please refer to the correct algo from here

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.