Java | Math | Array | Easy Solution
\nclass Solution {\n    public int nearestValidPoint(int x, int y, int[][] points) {\n        int min = Integer.MAX_VALUE,index=0;\n        for(int i=0;i<points
```\nclass Solution {\n    public int nearestValidPoint(int x, int y, int[][] points) {\n        int min = Integer.MAX_VALUE,index=0;\n        for(int i=0;i<points.length;i++){\n            int x1 = points[i][0];\n            int y1 = points[i][1];\n            if(x==x1 || y==y1){\n                if(Math.abs(x-x1)+Math.abs(y-y1)<min){\n                    min=Math.abs(x-x1)+Math.abs(y-y1);\n                    index=i;\n                }\n            }\n        }\n        if(min==Integer.MAX_VALUE)\n            return -1;\n        return index;\n    }\n}\n```\nKindly upvote if you like the code.
['Array', 'Math', 'Java']