Skip to content
← Back to the archive

18 September 2026 · Advanced track

Detector Gap Pairs

Advanced Lists Numbers

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 order
  • Each gain is an integer from 0 to 1,000,000
  • gap is an integer from 0 to 1,000,000
  • A pair must use two different positions in gains

Function signature

def count_gain_pairs(gains, gap):

Sign in to solve this bracket

Reading the problem is free for everyone. Opening the editor and solving it requires an account with Open Bracket+.