Why am I getting WA

Can anyone tell me why I’m getting WA for the problem:
https://www.codechef.com/LTIME99C/problems/KMAX2

My code:

import java.util.;
import java.lang.
;
import java.io.*;

class Codechef
{
static int solve(int arr[], int n, int k) {
int max = arr[0];
int res = 0, maxIndex = 0;
for(int i=1; i<n; i++) {
if(arr[i] > max) {
max = arr[i];
maxIndex = i;
}
}
if(maxIndex < k-1) {
return 0;
}
res = n-maxIndex;
return res;
}

public static void main (String[] args) throws java.lang.Exception
{
	Scanner scan = new Scanner(System.in);
	int t = scan.nextInt();
	for(int i=0; i<t; i++) {
		int n = scan.nextInt();
		int k = scan.nextInt();
		int arr[] = new int[n];
		for(int j=0; j<n; j++) {
			arr[j] = scan.nextInt();
		}
		System.out.println(solve(arr, n, k));
	}
}

}