Easy Solution🔥🔥O(N) Solution ; Detailed Explanation✌️✌️
Intuition\n Describe your first thoughts on how to solve this problem. \nHere, we simply need to check if the point is valid with the minimum Manhattan distance
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nHere, we simply need to check if the point is valid with the minimum **Manhattan distance** and return the index of it else return -1.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nHere the current location is given by x and y i.e. (x, y) coordinate.\n- ***The first FOR Loop***\nFirstly, we need to find the minimum Manhattan distance possible for the valid points\nThe valid point can be checked by the **if condition** for x and y to the corresponding x and y coordinates of the point.\nThen we will find the Manhattan Distance of the point from the current location and save this distance in **min** variable. This distance is updated accordingly with the minimum distance possible.\n- ***The second FOR Loop***\nNow, we will check which valid points have that minimum Manhattan Distance and return its index.\n\n- If there is no such valid point then return -1.\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n        int min = INT_MAX;\n        for(int i = 0; i < points.size(); i++) {\n            if( (x == points[i][0]) || (y == points[i][1]) ) {\n                int d = abs(points[i][0] - x) + abs(points[i][1] - y);\n                if(d < min) min = d; \n            }\n        }\n\n        for(int i = 0; i < points.size(); i++) {\n            if( (x == points[i][0]) || (y == points[i][1]) ) {\n                int d1 = abs(points[i][0] - x) + abs(points[i][1] - y); \n                if(d1 == min) return i;\n            }\n        }\n        return -1;\n    }\n};\n```
['C++']