In statistical arbitrage and spread trading at Jane Street and Jump Trading, quantitative researchers analyze the distribution of pairwise price spreads across recorded transactions.
Given an integer array of recorded execution prices prices of size , and an integer , the pairwise spread between any two distinct executions and () is .
There are total pairs.
Your Task
Implement smallest_distance_pair(prices: list[int], k: int) -> int that determines the -th smallest pairwise spread in time.
Constraints
Examples
prices = [1, 3, 1]
k = 1
# Pairs: (1, 3) diff 2; (1, 1) diff 0; (3, 1) diff 2.
# Sorted spreads: [0, 2, 2]. 1st smallest is 0.
# Output: 0
prices = [1, 6, 1]
k = 3
# Spreads: [0, 5, 5]. 3rd smallest is 5.
# Output: 5