Easy Java solution
\n# Code\n\nclass Solution {\n    public int nearestValidPoint(int x, int y, int[][] points) {\n       int index=-1;\n        int min_distance=Integer.MAX_VALUE
\n# Code\n```\nclass Solution {\n    public int nearestValidPoint(int x, int y, int[][] points) {\n       int index=-1;\n        int min_distance=Integer.MAX_VALUE;\n        for (int i = 0; i < points.length; i++) {\n                if(points[i][0]==x || points[i][1]==y){\n                    int distance=Math.abs(points[i][0]-x)+Math.abs(points[i][1]-y);\n                    if(distance<min_distance){\n                        min_distance=distance;\n                        index=i;\n                }\n            }\n        }\n\n        return index; \n    }\n}\n```
['Java']