Python O(N) time O(1) space
python\nclass Solution:\n\t"""\n\tIn this problem we will simply iterate over all the points and keep track of the point \n\twith the lowest Manhattan distance.
```python\nclass Solution:\n\t"""\n\tIn this problem we will simply iterate over all the points and keep track of the point \n\twith the lowest Manhattan distance. We only perform this check if either x,y of the point\n\tmatches our current x,y from the function.\n\t"""\n    def getManhattanDistance(self, point1: [int], point2: [int]):\n        x, y = point1\n        x2, y2 = point2\n        return abs(x-x2) + abs(y - y2)\n\n    def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n        min_manhattan_distance = float("inf")\n        min_manhattan_distance_index = -1\n        for i in range(len(points)):\n            point_x, point_y = points[i]\n            if point_x == x or point_y == y:\n                current_manhattan_distance = self.getManhattanDistance([x, y], points[i])\n                if current_manhattan_distance < min_manhattan_distance:\n                    min_manhattan_distance = current_manhattan_distance\n                    min_manhattan_distance_index = i\n        \n        return min_manhattan_distance_index\n```
['Python']