Wrong answer on case; showing -1 instead of 1


#1

Your submission failed for the following input:

A : [ 1, 2, 7, 0, 9, 3, 6, 0, 6 ]

Your function returned the following :

1

The expected returned value :

-1

number of elements greater than 3 i.e 6,7,9 => so the answer is 1 right!


#2

6 is present two times in the array. So, the number of elements greater than 3 is actually 4 and not 3. So, the output is -1.


#3

Here you need to also check for the n
just assume that A.get(i)=n , then the next n values will be greater surely if and only if the A.get(i) != A.get(i+1). Think in this way apply some sense while making changes according to size() of ArrayList. And then it will surely work for you.