Loading
Loading
A raffle lets people claim any integer as their ticket number. The log is messy: it contains duplicates, zeros, negative numbers and very large numbers.
Return the smallest positive integer that nobody claimed in tickets. Aim for linear time and only constant extra memory; you may rearrange the array.
tickets = [3, -2, 1, 6, 2][3, -2, 1, 6, 2]only values 1..5 can affect the answer[1, 2, 3, 6, -2]after placing 1, 2 and 3 at their homesindex 3 holds 64 is not home — 4 is the answer4Sign 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.
1, 2 and 3 are claimed; 4 is the smallest positive number nobody holds.
Example 2
1 through 4 are all claimed, so the answer is the next number, 5.