Code Room
CodingMediumcod-g1417
Subject Two pointersLevel Entry–Mid~14 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.