While submitting the code, it’s showing RUN ERROR in Test case 0, but test case 1 and 2 are successfully passed. Please resolve.
My Code is as follows:-
import java.util.;
import java.io.;
public class Main {
public static int lastIndex(int[] arr, int n, int i, int key){
if(i==n){
return -1;
}
int index = -1;
if(arr[i]==key){
index = lastIndex(arr, n, i+1, key);
if(index<i){
index = i;
}
}
else
index = lastIndex(arr, n, i+1, key);
return index;
}
public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
int[] arr = new int[n];
for(int i=0; i<n; i++){
arr[i]= Integer.parseInt(st.nextToken());
}
int m = Integer.parseInt(br.readLine());
System.out.println(lastIndex(arr, n ,0 ,m));
}
}