Getting runtime error with test input but submission is fully acceptable


#1

public class Solution {
public int perfectPeak(ArrayList A) {

int l[]=  new int [A.size()];
int r[]=  new int [A.size()];
l[0]=A.get(0);
r[A.size()-1]=A.get(A.size()-1);

for(int i=1;i<A.size();i++){
    l[i]=Math.max(l[i-1],A.get(i));
}

for(int i=A.size()-2;i>=0;i--){
    r[i]= Math.min(A.get(i),r[i+1]);
}

for (int i =1;i<A.size()-1;i++){
    if(A.get(i)>l[i-1]&&A.get(i)<r[i+1]){
        return 1;
    }
}

return 0;
}}

above is my code for the solution it is acceptable in submission but getting runtime error in test input,can somebody explain why?