Sliding Window Maximum

why we are deleting elements from front and not from back.

while(!q.empty() && q.front()<=i-k)
{
q.pop_front();
}

@subhamkumar341768 hii shubham understand this

after see this if u have any doubt please tell me first see this

I didn’t find anything related to my Q in this video. My Question is just why we are deleting front of queue not back.

Because at first when u push k values to the queue then after finding max u have to ignore the first value u have pushed because u have to slide window further to take new element bcz if u pop from back then u miss that element which u pop after current iteration thats why i give this video to just understand @subhamkumar341768

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.

Can you please explain me with the help of one example.

@subhamkumar341768
1 2 3 1 4 5 2 3 6 suppose this is an array and u take queue.then u put elements in queue according to condition of ques like k size like this then put first k elements then after that find max from queue then from array u have to put next element so u have to pop not from back bcz u need that element for next slide so u have to pop from front bcz in next slide there is no need of that element