All problems
Problem 1

The missing integer

A stream contains every integer from 00 to N−1N - 1 exactly once, except for one missing value. The order is arbitrary.

Return the missing integer.

Model

The argument n gives NN, where 1≤N≤10,0001 \le N \le 10{,}000. The stream contains N−1N - 1 integers. Each call to p1.next() consumes and returns the next integer. Consumed integers cannot be read again. Reading past the end stops execution.

int solve(int n)
int p1.next()
Consume and return the next integer in the stream.

Example

n = 6; stream = [0, 1, 3, 4, 5]
Output: 2

Limits

Log in to write a solution.