Find the missing number
A list contains n distinct integers from 0 through n, with one missing. Return that missing integer.
items = [3, 0, 1]
n = len(items)
print(n*(n+1)//2, sum(items))Reason about the state
The complete arithmetic sum minus the observed sum isolates the missing value. The formula uses constant extra space. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
A list contains n distinct integers from 0 through n, with one missing. Return that missing integer.
The explanation opens here once every check passes.