0 through n, which is n + 1 tickets in total. One of them got lost; the other n are in the array tickets in no particular order, with no number repeated.
Return the number of the lost ticket.
Try to solve it in O(n) time with O(1) extra memory.tickets=[4, 0, 2, 1] → 3
There are 4 tickets, so the numbers ran from 0 to 4. Only 3 is missing.
tickets=[1, 2] → 0
The numbers run from 0 to 2, and 0 is missing.
tickets=[0] → 1
The numbers run from 0 to 1; the last one, 1, is missing.
tickets are distincttickets=[4, 0, 2, 1]
3
Run checks the first 3 tests in your browser. Submit checks all 43 tests on the server, hidden ones included.