values. Count the elements x for which x + 1 is also in the array.
Repeated elements are each counted on their own.values=[4, 9, 5, 3] → 2
4 has a 5 and 3 has a 4; 9 and 5 have no successor. The answer is 2.
values=[6, 6, 7, 2] → 2
Both 6s are counted separately, and each has a 7. The answer is 2.
values=[0, 2, 4] → 0
values=[4, 9, 5, 3]
2
Run checks the first 3 tests in your browser. Submit checks all 121 tests on the server, hidden ones included.