readings. You are also given max_gap and tolerance.
Decide whether there are two **different** indices i and j such that both hold:
- |i - j| ≤ max_gap: the readings were taken close to each other;
- |readings[i] - readings[j]| ≤ tolerance: and they almost match.
Return True if such a pair exists and False otherwise.readings=[40, 15, 22, 38], max_gap=2, tolerance=5 → False
40 and 38 differ by only 2, but they are 3 positions apart, which is too far. The neighbouring pairs (40, 15), (15, 22), (22, 38) and the pairs one apart, (40, 22) and (15, 38), all differ by more than 5. No pair fits.
readings=[40, 15, 22, 38], max_gap=3, tolerance=5 → True
Now a distance of 3 is allowed, so 40 and 38 (indices 0 and 3) fit.
readings=[-7, -7], max_gap=1, tolerance=0 → True
readings=[40, 15, 22, 38], max_gap=2, tolerance=5
False
Run checks the first 3 tests in your browser. Submit checks all 213 tests on the server, hidden ones included.