Trains the technique from
LeetCode 3532Path Existence Queries in a Graph IThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A rack holds n instruments numbered 0 to n - 1. Instrument i reports the calibration reading nums[i], and the readings are handed over already sorted in non-decreasing order.
Two instruments can talk to each other directly when their readings sit within maxDiff of one another, that is when abs(nums[i] - nums[j]) <= maxDiff. A calibration signal may also be relayed: it travels from one instrument to another whenever some chain of direct links connects them, with any number of hops in between.
Each entry of queries is a pair [u, v]. Return an array of booleans, one per query in the same order, saying whether a signal can get from instrument u to instrument v. An instrument can always reach itself.
Example 1
Readings 2, 3, 4 and 6 form one relay chain because each neighbouring step is 1, 1 and 2. The reading 9 is 3 above 6 and further from the rest, so nothing links it, and a query onto itself is still true.
Example 2
Only identical readings can talk when maxDiff is 0, so instruments 0 and 1 are linked and instrument 2 stands alone.
Example 3
Instrument 0 links to 1 and 1 links to 2, each step being exactly 10, so a relayed signal covers 0 to 2 even though their own readings differ by 20.
Example 4
Instruments 0 and 1 sit together with a step of 1. Instruments 2, 3 and 4 form a second group, their neighbouring steps being 1 and 1. Instrument 5 reads 40, which is 31 above its nearest neighbour, so it links to nothing.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def sync_reachability(count: int, readings: list[int], max_gap: int, pairs: list[list[int]]) -> list[bool]:public boolean[] syncReachability(int count, int[] readings, int maxGap, int[][] pairs)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.