values and a positive integer step. In one move you may pick any element and either add step to it or subtract step from it. You may make any number of moves, including none.
The **MEX** of an array is the smallest non-negative integer that does not appear in it. For example, the MEX of [3, 0, -2] is 1, and the MEX of [1, 2] is 0.
Return the largest MEX you can reach with these moves.values=[8, -3, 6, 1, 3], step=4 → 4
8 → 0, -3 → 1, 6 → 2, 3 → 3. Getting 4 would need another element with remainder 0 modulo 4, but the only one (8) is already used for 0. The answer is 4.
values=[2, 2, 2], step=1 → 3
With a step of 1 any element can become any number: make 0, 1 and 2, which gives 3.
values=[5, 10], step=5 → 1
values=[8, -3, 6, 1, 3], step=4
4
Run checks the first 3 tests in your browser. Submit checks all 117 tests on the server, hidden ones included.