Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+37 votes

Not super sure what the outcome here is supposed to be. Are we just testing to see if there's ever more than 2 adjacent scores more than 2 points off? Or should every score not be more than 2 points off from each other (so we would need a cumulative count of the differences of adjacent scores)? I'm just confused.

asked in CSC285_Fall2018 by (8 points)

5 Answers

+25 votes
 
Best answer

It's basically asking if the array contains three consecutive numbers in which all three are within a range of two from one another. So, you don't want the difference between any of those three numbers to be greater than two. For example, 123 works, but 124 does not. Although 4 - 2 = 2 and 2 - 1 = 1, 4-1=3 which messes up the whole thing. This only needs to happen once in the array. It does not need to happen with every single group of 3. Also, a hint/solution from array123 might be slightly helpful with this problem.

answered by (8 points)
selected by
+23 votes

The generally confusing point is that you have to consider the numbers in groups of three adjacent numbers:

e.g. 1 4 7 8 9 100 has a 3-element "clump" somewhere in the middle with 7 8 9, where they're all within 2 of each other.

answered by (17.9k points)
+21 votes

What helped me think about it is just visualize the array as segments of 3. Make sure to analyze all the possible segments of 3. If at any point any segment differs but 2 or less from its smallest to largest value, then it's true.

answered by (1.9k points)
+19 votes

-Basically it's false if:
+The three numbers are not in the increasing order
AND
+The difference between the 3rd number (which is supposed to be the largest one) and the 1st/2nd number is greater than 2.
-Ex:
+True: 1-2-3, 1-2-2
+False: 1-2-4, 1-1-4

answered by (8 points)
+18 votes

The question just ask about that there is 3 number next to each other, and not any number over 2 other number or not. If they exist, this method should return true.

answered by (4.8k points)
...