Test Cases not passing. I created following function

public static void StrongestFighter(int[] arr,int k) {
int i;
Deque deque=new LinkedList();
for(i=0;i<k;i++) {
while(!deque.isEmpty()&&arr[i]>arr[deque.getLast()]) {
deque.removeLast();
}
deque.addLast(i);
}
for(;i<arr.length;i++) {
System.out.print(arr[deque.getFirst()]+" ");
while(!deque.isEmpty()&&deque.getFirst()<=i-k) {
deque.removeFirst();
}
while(!deque.isEmpty()&&arr[i]>arr[deque.getLast()]) {
deque.removeLast();
}
deque.addLast(i);
}
System.out.println(arr[deque.getFirst()]);
}

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

I have mentioned the error line in the corrected code.

Also, use peek instead of get.

Reason:

the getFirst method throws NoSuchElementException when the list is empty
but the peekFirst method throws null in case of empty list. Hence preventing a run time error.