FunctionRacerProblemsRace

Closest to Target

EasyNumPyPython

Return the index of the number in nums that is closest to target (smallest |x - target|). If two numbers are equally close, return the smaller index.

Example 1

nums [1,6,10]
target 7
returns 1

6 is only 1 away from 7.

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 NumPy problems