Assignment:

Given an array of scores sorted in increasing order, return true if the array contains 3 adjacent scores that differ from each other by at most 2, such as with {3, 4, 5} or {3, 5, 5}.

scoresClump({3, 4, 5}) → true

scoresClump({3, 4, 6}) → false

scoresClump({1, 3, 5, 5}) → true

Codingbat AP-1 3rd question

I got it right for some of the input, but not one of them. I tried to use the for loop and if statement on a specific input that I got wrong:

{4, 5, 8}

scores[1] - scores[0] = 1

scores[2] - scores[1] = 3

I suspect it has something to do with the for loop, but I don't see the problem with it. It should work, shouldn't it?

But anyway, here is the error for {4,5,8} :

Exception:java.lang.ArrayIndexOutOfBoundsException : 3 (line number:7)