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

Find The Tightest Bid Ask Spread

Given N top-of-book snapshots, each contains an integer bid and ask with ask at least bid.

Given N top-of-book snapshots, each contains an integer bid and ask with ask at least bid. Print the smallest ask minus bid across all snapshots. Prices are expressed in ticks, not floating-point currency.

Input format

First line N; next N lines bid ask.

Output format

Print one nonnegative integer: the minimum spread.

Examples

Example 1
Input
3
100 103
102 103
98 105
Expected output
1

Constraints

  • 1 ≤ N ≤ 100000
  • 0 ≤ bid ≤ ask ≤ 10^9

Related concepts

Spreads

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
3
100 103
102 103
98 105
Expected output
1
Execution requires a secure external judge.