Loading
Loading
A raffle printed tickets numbered 0 to n, one of each. At the draw, the organisers scan every ticket in the drum and find that exactly one number never turned up.
Given the tickets that were scanned (n distinct numbers, in any order, drawn from 0 to n), return the one number from 0 to n that is missing.
tickets = [3, 0, 4, 1]acc = 4start with n = 4, the one index the loop never visitsacc = 4 ^ 0 ^ 3index 0, ticket 3acc ^= 1 ^ 0index 1, ticket 0acc ^= 2 ^ 4index 2, ticket 4acc ^= 3 ^ 1index 3, ticket 1acc = 20, 1, 3 and 4 each appear twice and cancel2Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n) time · O(1) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
Tickets 0 to 4 were printed; 2 is the one not scanned.
Example 2
Tickets 0 to 2 were printed; 0 is missing.