Code RoomPair with exact difference
MediumPrep Room Coding #613

Pair with exact difference

CodingAlgorithms & data structuresEntry–Mid~14 min

Given a sorted array of distinct integers nums and a positive integer d, return True if some pair of elements differs by exactly d, and False otherwise. Use two pointers that both move forward (a fast and a slow index) for an O(n) scan — no nested loops, no hash set. Example: nums = [1, 3, 6, 10], d = 4 gives True because 10 - 6 = 4.

Implement
has_pair_with_gap(nums: list[int], d: int) → bool
Examples
in[[1,3,6,10],4]outtrue
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 14 min
InputExpectedGot
[[1,3,6,10],4]truenot run yetsample