C++ Solution for beginners
\nclass Solution {\npublic:\n    int nearestValidPoint(int x1, int y1, vector<vector<int>>& arr) {\n        \n        int ans_dis=INT_MAX;\n        int ans_idx=
```\nclass Solution {\npublic:\n    int nearestValidPoint(int x1, int y1, vector<vector<int>>& arr) {\n        \n        int ans_dis=INT_MAX;\n        int ans_idx=-1;\n\n        for(int i=0;i<arr.size();i++)\n        {\n            int x2=arr[i][0];\n            int y2=arr[i][1];\n\n            if(x1==x2 or y1==y2)\n            {\t\n                int dis = abs(x1 - x2) + abs(y1 - y2);\n\n                if(dis < ans_dis)\n                {\n                   ans_dis = dis;\n                   ans_idx=i;\t\n                }\t\n            }\n            else\n            continue;\n        }\n        return ans_idx;\n    }\n};\n```
['Array', 'C', 'C++']