Strongest Fighter or Maximum element in every window of size K

Please check my code its not passing any of the cases but I’ve seen the sample case its giving correct ans

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.Deque;

import java.util.LinkedList;

import java.util.Scanner;

public class Main {

public static void main(String args[]) throws  

IOException {

Scanner sc = new Scanner(System.in);

	int n=0;

	if(sc.hasNextInt()){

		n = sc.nextInt();

	}
	int[] strength = new int[n];
	for(int i=0;i<n;i++) {
		if(sc.hasNextInt()){
			strength[i]=sc.nextInt();
		}
	}
	int k=0;
	if(sc.hasNextInt()){
 		k =sc.nextInt();
	}
	getStrengths(strength,k);
	sc.close();
}
private static void getStrengths(int[] arr, int k) {
	
	Deque<Integer> q = new LinkedList<>();
	int i;
	for( i=0;i<k;i++) {
		if(!q.isEmpty() && arr[i]>arr[q.getLast()]) {
			q.removeLast();
		}
		q.addLast(i);
	}
	
	for(;i<arr.length;i++) {
		
		System.out.print(arr[q.getFirst()] + " ");
		while(!q.isEmpty() && q.getFirst()<=i-k) {
			q.removeFirst();
		}
		
		while(!q.isEmpty() && arr[i]>arr[q.getLast()]) {
			q.removeLast();
		}
		q.addLast(i);
	}
	
	System.out.println(arr[q.getFirst()]);
}

}

hey @Ritik488 just a change
Deque q = new LinkedList<>();
int i;
for (i = 0; i < k; i++) {
// while instead of if
while (!q.isEmpty() && arr[i] > arr[q.getLast()]) {
q.removeLast();
}
q.addLast(i);
}
correct code