What wrong in my code three cast case is failed

#include
using namespace std;
#include
void window(deque g,int a[],int n,int k){
int max=0;
int f=0;;
for(int i=0;i<k;i++){
if(max<a[i]){
max=a[i];
f=i;
}}
for(int l=f;l<k;l++){
g.push_back(l); }

   for(int d=k;d<n;d++){
       cout<<a[g.front()]<<" ";
   while(!g.empty()&&a[d]>=a[g.back()]){
      g.pop_back();
   }
       while((!g.empty())&&(g.front()<=(d-k))){
           g.pop_front();
       }
       
       g.push_back(d);
        
   }
   cout<<a[g.front()];

}
int main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
int k;
cin>>k;
deque g;
window(g,a,n,k);

return 0;

}

for (int i = 0; i < k; i++)
    {
        if (mx< a[i])
        {
            mx= a[i];
            f = i;
        }
    }
    for (int l = f; l < k; l++)
    {
        g.push_back(l);
    }

Your code is failing in these lines,
u have to mantain the dequeue in a fashion of decreasing order of valued index.
Try something like this for the first k elements:

for(int i = 0 ; i < k ; i++){
while((!q.empty()) and a[i] > a[q.front()])
q.pop_back();
q.push_back(i);
}

In case of further doubts do ask.

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.