Beats 97.73%
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nfunction nearestValidPoint(x: number, y: number, points: number[][]): number {\n\n    let smallDistance = Number.MAX_SAFE_INTEGER;\n    let smallIndex = -1;\n\n    for(let i=0;i<points.length;i++){\n        const distance = Math.abs(points[i][0] - x) \n                       + Math.abs(points[i][1] - y);\n\n        if((points[i][0] === x || points[i][1] === y) && distance < smallDistance){\n            smallDistance = distance;\n            smallIndex = i;\n        } \n    }\n    return smallIndex;\n};\n```
['TypeScript']