FunctionRacerProblemsRace

Close in Place and in Value

HardHash mapsPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Hash maps problems