[C++] Easy solution || 100% Time || 100% Space
Simple solution in O(n) complexity.\n\nC++\n\nclass Solution {\npublic:\n    int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n        int pos
Simple solution in `O(n)` complexity.\n\n**C++**\n```\nclass Solution {\npublic:\n    int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n        int pos = -1;\n        int ans = INT_MAX;\n        \n        for(int i=0; i<points.size(); i++){\n            if(points[i][0] == x or points[i][1] == y){\n                int dist = abs(x-points[i][0]) + abs(y-points[i][1]);\n                if(dist < ans){\n                    pos = i;\n                    ans = dist;\n                }\n            }   \n        }\n       return pos;\n    }\n};\n```
['C', 'C++']