values of length n, and every number in it lies between 1 and n. Some numbers may repeat, which means others may not appear at all.
Return, in increasing order, every number from 1 to n that is absent from the array.
Try to do it in O(n) time with no extra memory beyond the answer.values=[2, 2, 5, 1, 5] → [3, 4]
The length is 5, so the numbers 1 to 5 are expected. 1, 2 and 5 are there; 3 and 4 are missing.
values=[3, 1, 2] → []
Every number from 1 to 3 is present, nothing is missing.
values=[1, 1, 1, 1] → [2, 3, 4]
n = values.length ≤ 10⁵values[i] ≤ nvalues=[2, 2, 5, 1, 5]
[3, 4]
Run checks the first 3 tests in your browser. Submit checks all 58 tests on the server, hidden ones included.