Simple Java Solution
\nclass Solution {\n    public int nearestValidPoint(int x, int y, int[][] points) {\n        int smallest  = Integer.MAX_VALUE ;\n        int k = -1;\n        
```\nclass Solution {\n    public int nearestValidPoint(int x, int y, int[][] points) {\n        int smallest  = Integer.MAX_VALUE ;\n        int k = -1;\n        for(int i = 0;i<points.length;i++){\n            if(points[i][0]==x || points[i][1]==y ){\n                if( Math.abs((points[i][0]-x)) +  Math.abs((points[i][1]-y))<smallest){\n                    smallest = Math.abs((points[i][0]-x)) + Math.abs((points[i][1]-y));\n                    k=i;\n                }\n            }\n        }\n        return k;\n    }\n}\n```\n``` If You Found This Helpful Then Do UpVote Plz```
['Java']