FunctionRacerProblemsRace

Evenly Spaced Picks

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

Pick three or more items of nums and keep them in their order. The picked items do not have to be neighbors. A pick is evenly spaced when each picked item minus the one picked before it gives the same number every time.

Return how many evenly spaced picks there are. Picks that use different positions count separately, even when their values are equal.

Example 1

nums [1,2,3,4]
returns 3

The picks are 1 2 3, then 2 3 4, then 1 2 3 4.

Example 2

nums [5,5,5,5]
returns 5

Any three of the four items work (4 picks), and so do all four together.

Example 3

nums [1,3,9]
returns 0

The steps are 2 and 6, so the only pick of three items is not evenly spaced.

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