✅ Best and Easy solution 100% ✅
\n\n# Code\n\nclass Solution {\n    public int nearestValidPoint(int x, int y, int[][] mat) {\n        int min =10001;\n        int pos=-1;\n\n        for(int i
\n\n# Code\n```\nclass Solution {\n    public int nearestValidPoint(int x, int y, int[][] mat) {\n        int min =10001;\n        int pos=-1;\n\n        for(int i=0; i<mat.length; i++){\n            if(mat[i][0]==x || mat[i][1]==y){\n                int val = Math.abs(mat[i][0]-x)+Math.abs(mat[i][1]-y);\n                if(val<min){\n                    min=val;\n                    pos=i;\n                }\n            }\n        }\n        return pos;\n    }\n}\n```
['Array', 'Java']