python solution easy to understand O(n) , O(1)
Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n# Code\n\nclass Solution:\n    def nearestValidPoint(self, x: int, y: int, points: List[List[in
# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n# Code\n```\nclass Solution:\n    def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n\n        minn=float(\'inf\')\n        index=-1\n        for i , v in enumerate(points):\n            if v[0]==x or v[1]==y:\n                man_dis=abs(x - v[0]) + abs(y - v[1])\n                if(man_dis<minn) :\n                    minn=man_dis\n                    index=i\n        \n        return index\n```
['Python3']