Detect Missing Market Data Sequence Numbers
Count dropped sequence numbers in a strictly increasing market data stream.
A market-data publisher labels messages with monotonically increasing sequence numbers. A gap of size k between two received messages indicates k-1 missing messages. Count all missing messages. Input sequence numbers are strictly increasing.
Input format
First line: N. Second line: N space-separated sequence numbers.
Output format
Print the number of missing sequence numbers between the first and last received messages.
Examples
5 12 13 16 17 19
3
Messages 14, 15 and 18 are missing.
Constraints
- 1 ≤ N ≤ 100000
- 0 ≤ sequence[i] ≤ 10^12
- sequence[i] < sequence[i+1]
Related concepts
This early-access exercise uses standard input/output. More advanced concurrency challenges will use specialized class interfaces, instrumentation, and stress tests once the judging infrastructure is ready.
Loading Monaco C++ editor…
Checking whether the external C++ judge is available.
5 12 13 16 17 19
3