Wrong output in "Strongest Fighter" problem

Following code is giving wrong answer in first three test cases.

import java.util.*;
public class Main
{
int data[];
int front;
int size;
public static final int DEFAULT_CAPACITY=10;
public Main() throws Exception
{
this(DEFAULT_CAPACITY);
}
public Main(int capacity) throws Exception
{
if(capacity<1)
throw new Exception(“Invalid capacity”);
this.data=new int[capacity];
this.front=0;
this.size=0;
}
public int size()
{
return(this.size);
}
public boolean isEmpty()
{
return(this.size==0);
}
public void enqueue(int value) throws Exception
{
if(this.size()==this.data.length)
throw new Exception(“Queue is full.”);
int ai=(this.front+this.size)%this.data.length;
this.data[ai]=value;
this.size++;
}
public int dequeue() throws Exception
{
if(this.size==0)
throw new Exception(“Queue is empty.”);
int rv=this.data[this.front];
this.data[this.front]=0;
this.front=(this.front+1)%this.data.length;
this.size–;
return rv;
}

public void find(int k) throws Exception
{
    int i=2;
    int n;
    int temp=this.dequeue();
    while(i<=k)
    {
        n=this.dequeue();
        if(n>temp)
        {
            temp=n;
            i++;
        }
        else
            i++;
    }
    System.out.print(temp+" ");
    while(!this.isEmpty())
    {
        n=this.dequeue();
        if(n>temp)
            temp=n;
        System.out.print(temp+" ");
    }
}

public static void main(String[] args) throws Exception
{
    Scanner sc=new Scanner(System.in);
    int N=sc.nextInt();
    Main queue=new Main(N);
    for(int i=1;i<=N;i++)
    {
        int n=sc.nextInt();
        queue.enqueue(n);
    }
    int k=sc.nextInt();
    queue.find(k);
}

}

@vinay86048,
Suggested approach:

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.

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.