Nearest Aligned Point
You are at (x, y). A point in points is aligned with you if it has the same x or the same y as you. Among the aligned points, find the one with the smallest Manhattan distance |x - px| + |y - py| and return its index in points. If several are tied, return the smallest index. If no point is aligned, return -1.
Example 1
x 3
y 4
points [[1,2],[3,1],[2,4],[2,3],[4,4]]
returns 2
Aligned: index 1 (distance 3), 2 (1), 4 (1). Smallest index with distance 1 is 2.
Constraints
0 <= len(points) <= 100- Coordinates are between -100 and 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.