O(n): put all in a set; only start a streak when x-1 not in set.
x-1
Input
6 100 4 200 1 3 2
Output
4
10 0 3 7 2 5 8 4 6 0 1
9