C++
\nclass Solution {\npublic:\n    int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n        int n = points.size();\n        int temp = INT_MAX;
```\nclass Solution {\npublic:\n    int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n        int n = points.size();\n        int temp = INT_MAX;\n        int distance;\n        int ans = INT_MIN;\n        for(int i = 0; i < n; i++) {\n            if(points[i][0] == x || points[i][1] == y) {\n                distance = (abs(x-points[i][0]) + abs(y-points[i][1]));\n                if (temp > distance) {\n                    temp = distance;\n                    ans = i;\n                } \n            }\n        }\n         return ans == INT_MIN ? -1 : ans;\n    }\n};\n```
['C']