FunctionRacerProblemsRace

Nearby Duplicate

EasyHash mapsPython, JavaScript, TypeScript, Java, C++

Return True if the list nums has two different positions i and j with nums[i] == nums[j] and abs(i - j) <= k (k is the second argument). Otherwise return False.

Example 1

nums [1,2,3,1]
k 3
returns true

The 1s are at positions 0 and 3, distance 3, which is allowed.

Example 2

nums [1,2,3,1]
k 2
returns false

The 1s are 3 apart, more than 2.

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