Account
Draft saved on this device
▤ DescriptionOriginal CppValley problem
HFT SystemsMedium

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

Example 1
Input
5
12 13 16 17 19
Expected output
3

Messages 14, 15 and 18 are missing.

Constraints

  • 1 ≤ N ≤ 100000
  • 0 ≤ sequence[i] ≤ 10^12
  • sequence[i] < sequence[i+1]

Related concepts

Market DataSequencesValidation

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.

⌘ CodeC++17
GNU C++17 · main.cpp

Loading Monaco C++ editor…

Checking judge...

Checking whether the external C++ judge is available.

⌁ Test cases & resultsPublic samples: 1
Input
5
12 13 16 17 19
Expected output
3
Execution requires a secure external judge.