Closest to Origin
points is a 2-D array with one point per row, as [x, y]. Return the row number of the point closest to the origin (0, 0). If two points are equally close, return the smaller row number. Hint: you can compare x * x + y * y instead of taking square roots.
Example 1
points [[3,4],[1,1],[-2,0]]
returns 1
The distances are 5, about 1.41 and 2, so row 1.
Constraints
1 <= len(points) <= 50
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More NumPy problems
- Closest to TargetEasy
- Column MaximumsEasy
- Column WinnersEasy
- Compound GrowthEasy
- Count BetweenEasy
- Count IncreasesEasy
- Count Sign ChangesEasy
- Drop Lowest AverageEasy