Some testcase are working

please me out. the code is not working for some testcases i need help;

@shudhanshu20092001_af6f20d24c617008 Your logic fails for testcase like :
8
9 6 2 5 1 2 3 4
3
Bcoz Your queue.peek() will always give 9 since it is the largest element in the array and that also in the first window so you will always get 9.
Your output : 9 9 9 9 9 9 9
Correct Output : 9 6 5 5 3 4.
Correct Logic is given below :
Efficient Approach - (Sliding Window Technique using Deque)
We create a Deque, Qi of capacity k, that stores only useful elements of current window of k elements. An element is useful if it is in current window and is greater than all other elements on left side of it in current window. We process all array elements one by one and maintain Qi to contain useful elements of current window and these useful elements are maintained in sorted order. The element at front of the Qi is the largest and element at rear of Qi is the smallest of current window.

Figure

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.