Close in Place and in Value
Return True if nums has two different positions that are at most reach apart and hold values that differ by at most gap, otherwise False.
Example 1
nums [4,9,1,6]
reach 3
gap 2
returns true
The values 4 and 6 are three positions apart and differ by 2.
Example 2
nums [4,9,1,6]
reach 2
gap 2
returns false
Now 4 and 6 are too far apart, and every pair within two positions differs by 3 or more.
Constraints
2 <= len(nums) <= 3001 <= reach <= len(nums)0 <= gap <= 10**9-109 <= nums[i] <= 109
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.