values. Pick some of its elements (any of them may be skipped) so that the largest picked value is exactly 1 greater than the smallest one.
Return the largest number of elements you can pick this way. If no such pick exists (for instance, all values are equal or no two of them differ by 1), return 0.values=[4, 7, 5, 4, 6, 5, 4] → 5
Take every 4 and every 5: [4, 5, 4, 5, 4] has maximum 5 and minimum 4, five elements in total. Pairing 5 with 6 or 6 with 7 gives fewer.
values=[10, 12, 14] → 0
No two values differ by exactly 1, so the answer is 0.
values=[-1, 0, 0, -1, 2] → 4
values=[4, 7, 5, 4, 6, 5, 4]
5
Run checks the first 3 tests in your browser. Submit checks all 115 tests on the server, hidden ones included.