Maximum element deque STL

INPUT= 123456 (I’m taking sample case of my own)

So, in this question we first process k elements separately
by using ’ i ’ as our iteration variable so our window is (123) for k=3. I completely understood this part but when we process next window we are simply skipping initialization of ’ i ’ in loop (line number 29). And, now our window will be from (345) right?? because we processed first k elements separately but don’t you think we should first process (234) because that way we are incrementing our window by 1. I hope I made myself clear!

hello @div_yanshu07

here u went wrong. value of i after processing first k elements will be k (becuase 0 based indexing) .
so the first window that we will consider in second for loop will be [2,3,4] -> [ i-k+1…i].

i will become k right i=3
Now in second loop we are not initializing i so our i will be at 3rd index only right??
How i is becoming 1?

ok let me clear this first.
i (in second loop) -> it is index of right most element of current window.
starting index is i-k+1 .
so when i is 3 (ending index). then i-k+1 -> 3-3+1 = 1 wiil be starting index of the considered window

Okay, I did a dry run. Now, I understood we are handling that case inside the loop. Thank you!

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.