Closest to Target
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
1 <= len(nums) <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More NumPy problems
- Column MaximumsEasy
- Column WinnersEasy
- Compound GrowthEasy
- Count BetweenEasy
- Count IncreasesEasy
- Count Sign ChangesEasy
- Drop Lowest AverageEasy
- Empty SeatsEasy