✅ Easy C++ O(N) Soln. [ FAANG😱 Interview Optimized code ]
Find Nearest Point That Has the Same X or Y Coordinate\n1) Loop through the vector of points.\n2) If x or y coordinate matches, Calculate and record manhatten d
`Find Nearest Point That Has the Same X or Y Coordinate`\n1) Loop through the vector of points.\n2) If x or y coordinate matches, Calculate and record manhatten distance for every point.\n3) Compare every time if manhattan distance is lesser than the previous recorded least distance.\n4) Return the least distance point\'s index no. \n\n# **Pretty ez question ig ! Really good for beginners !  \uD83D\uDD25**\n\n```\nTC: O(n)\nSC: O(1)\n```\n\n```\nclass Solution {\npublic:\n    int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n        int manhattan,d=INT_MAX,ans=-1;\n        for(int i=0;i<points.size();i++){\n            if(points[i][0]==x || points[i][1]==y){\n                manhattan=abs(x - points[i][0]) + abs(y - points[i][1]);\n                if(manhattan<d){\n                    d=manhattan;\n                    ans=i;\n                }\n            }\n        }\n        return ans;\n    }\n};\n```\n# ***Please upvote if it helps \uD83D\uDE4F.***
['Array', 'C', 'Python', 'C++', 'Java']