Integers randomness problem.

An array of random integers doesn't usually have to be sorted.

The function will return 0 instead of 4 in this case: f(2, [3, 3, 1, 1]) even if 3 - 1 = 2