Find the Missing Number with Cyclic Sort
Send every number to the index that matches its value, then find the empty seat.
The problem
Implement missing_value_cyclic(values). The list values holds n distinct integers taken from the range 0 to n, so exactly one number in that range is missing. Return the missing number. Do not change values itself; if you want to rearrange numbers, rearrange a copy. For example, [3, 0, 1] is missing 2, and [0, 1, 2] is missing 3. Constraints: 1 <= n <= 10000.
Starter code
def missing_value_cyclic(values):
passPublic examples
values = [3, 0, 1]gives2values = [0, 1, 2]gives3values = [2, 0, 3]gives1
Solving it in the practice book needs an active paid plan.
Open it in the practice bookOne thought at a time.
