First 3 cases not passing

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] arr=new int[n];
for(int i=0;i<n;i++) {
arr[i]=sc.nextInt();
}
int k=sc.nextInt();
sc.close();
printMax(arr,k);
}
public static void printMax(int[] arr, int k) {
Deque ansDeque=new LinkedList();
int i;
for(i=0;i<k;i++) {
while(!ansDeque.isEmpty()&&arr[i]>arr[ansDeque.getLast()]) {
ansDeque.removeLast();
}
ansDeque.addLast(i);
}
for(;i<arr.length;i++) {
System.out.print(arr[ansDeque.getFirst()]+" “);
while(!ansDeque.isEmpty()&&ansDeque.getFirst()<i-k) {
ansDeque.removeFirst();
}
while(!ansDeque.isEmpty()&&ansDeque.getLast()<arr[i]) {
ansDeque.removeLast();
}
ansDeque.addLast(i);
}
System.out.print(arr[ansDeque.getFirst()]+” ");
}

@Rishabh8488,
https://ide.codingblocks.com/s/252459 corrected code.

Your approach is correct. Just a few small mistakes here and there.

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.