18 September 2026 · Advanced track
Detector Gap Pairs
Count the distinct pairs of detector gains separated by an exact gap.
An observatory keeps its detector gain settings in sorted order. You are given that sorted list and a non-negative target gap. Two different positions form a match when the larger gain minus the smaller gain is exactly the target gap. Return the number of distinct gain-value pairs that match. If the same gain value appears more than once, count a matching pair of equal values only once when the target gap is 0. Repeated copies of any other matching values also count as one pair.
Constraints
gains contains from 0 to 20,000 integers in non-decreasing orderEach gain is an integer from 0 to 1,000,000gap is an integer from 0 to 1,000,000A pair must use two different positions in gains
Function signature
def count_gain_pairs(gains, gap):