MY OUTPUT IS COMING OUT TO BE INCORRECT

#include
#include
using namespace std;

int main()
{
int n;
int a[100000];
int k;

cin>>n;
for(int i=0;i<n;i++)
   cin>>a[i];

cin>>k;

// we have to process first k elements seprately

deque<int> Q(k);

int i;
for(i=0;i<k;i++)
{
    while(!Q.empty() && a[0]>a[Q.back()])
    {
        Q.pop_back();
    }
    Q.push_back(i);
}
// process the remaining elements

for(;i<n;i++)
{
    cout<<a[Q.front()]<<" ";
    
    // 1. Remove the elements which are not part of window
    while((!Q.empty() && (Q.front()<=i-k)))
    {
        Q.pop_front();
    }
    
    
    // 2. Remove the elements which are not useful and part of window
    while(!Q.empty() && a[i]>=a[Q.back()])
    {
        Q.pop_back();
    }
    
    // 3. Add new elements
    Q.push_back(i);
}

cout<<a[Q.front()]<<" ";

}

hi @Mukul-Shane-1247687648773500, in first for loop write a[i] not a[0]

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.