Simple JAVA 2MS answer
\nclass Solution {\n    public int nearestValidPoint(int x, int y, int[][] points) {\n        int result = -1;\n        int distance = Integer.MAX_VALUE;\n     
```\nclass Solution {\n    public int nearestValidPoint(int x, int y, int[][] points) {\n        int result = -1;\n        int distance = Integer.MAX_VALUE;\n        for(int i = 0;i<points.length;i++)\n        { \n          int x1 = points[i][0];\n          int y1 = points[i][1];\n         if(x1 == x || y1 == y)\n         {  \n             int temp = Math.abs(x1-x) + Math.abs(y1-y);  \n            if(distance > temp)\n           {  \n              distance = temp;\n              result = i;\n           }\n         }  \n            \n        }\n        return result;\n    }\n}\n```
[]