Go one pass easy hehe
\nfunc nearestValidPoint(x int, y int, points [][]int) int {\n    var res int = -1\n    \n    smallestDistance := 1 << 63 - 1\n    \n    for i := 0; i < len(poi
```\nfunc nearestValidPoint(x int, y int, points [][]int) int {\n    var res int = -1\n    \n    smallestDistance := 1 << 63 - 1\n    \n    for i := 0; i < len(points); i++ {\n        if points[i][0] == x || points[i][1] == y {\n            if distance([]int{x, y}, points[i]) < smallestDistance {\n                smallestDistance = distance([]int{x, y}, points[i])\n                res = i\n            }\n        }\n    }\n    \n    return res\n}\n\nfunc distance(a []int, b[]int) int {\n    return (a[0] - b[0])*(a[0] - b[0]) + (a[1] - b[1])*(a[1] - b[1])\n}\n```
['C', 'Python', 'Java', 'Go']