Easy C++ solution || Beginner-friendly
\n\n# Code\n\nclass Solution {\npublic:\n    int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n        int ans=-1, min=INT_MAX;\n        for(i
\n\n# Code\n```\nclass Solution {\npublic:\n    int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n        int ans=-1, min=INT_MAX;\n        for(int i=0; i<points.size(); i++)\n        {\n            int a = points[i][0];\n            int b = points[i][1];\n            if(a==x || b==y)\n            {\n                int val = abs(x-a)+abs(y-b);\n                if(val<min){\n                    ans=i;\n                    min=val;\n                }\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']