Solved with using boolean array
Intuition\n Describe your first thoughts on how to solve this problem. \nIn this question it is the main thing is \nVALID - Points having either x or y or both 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIn this question it is the main thing is \nVALID - Points having either x or y or both \nNOT VALID  - Points dont having x or y\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSo will take an boolean array from which we will check its a valid point or not.\nValid point will be declared as true and non valid as false.\n\nThen we will travserse the array and store the minimum value in the variable and return that value;\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n# Code\n```\nclass Solution {\n    public static int nearestValidPoint(int x, int y, int[][] points) {\n        boolean flag[] = new boolean[points.length];\n        int min = Integer.MAX_VALUE;\n        int reqindex = -1;\n        \n        for (int i = 0; i < points.length; i++) {\n            if (points[i][0] == x || points[i][1] == y) {\n                flag[i] = true;\n            }\n        }\n        \n        for(int i=0; i<flag.length; i++){\n            if(flag[i]){\n                int value =    Math.abs(x - points[i][0]) + Math.abs(y - points[i][1]);\n                if(value < min){\n                    min = value;\n                    reqindex = i;\n                }\n            }\n        }\n        return reqindex;                \n        }   \n\n}\n```
['Array', 'Java']