question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
find-nearest-point-that-has-the-same-x-or-y-coordinate | Simple for Beginners Java Approach | simple-for-beginners-java-approach-by-ja-xvcv | Q & A\n##### Q1: Why have you initialized index with -1 and not 0?\n##### \n##### A1: Make the code more general. e.g., If no point has the same x or y coordina | jainshubham766 | NORMAL | 2022-03-18T06:22:53.586989+00:00 | 2022-03-18T06:22:53.587034+00:00 | 4,060 | false | ##### Q & A\n##### Q1: Why have you initialized index with -1 and not 0?\n##### \n##### A1: Make the code more general. e.g., If no point has the same x or y coordinate, then we can still detect it by the return value. Otherwise, if the return value is 0, we would NOT know whether the point at index 0 is the solution o... | 48 | 0 | ['Java'] | 1 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | ✅ O(N) Simple solution w/ explanation | C++ short & concise | on-simple-solution-w-explanation-c-short-fjwz | We can simply iterate over all the points in points array and if a point is valid (has the same x or y co-ordinate as our location), find its manhattan distance | archit91 | NORMAL | 2021-03-06T16:02:20.395418+00:00 | 2021-05-25T17:25:12.304874+00:00 | 4,174 | false | We can simply iterate over all the points in `points` array and if a point is valid (has the same `x` or `y` co-ordinate as our location), find its *manhattan distance* and remember its index if that is the minimum one. Lastly, just return the index.\n```\nint nearestValidPoint(int x, int y, vector<vector<int>>& points... | 38 | 4 | [] | 5 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | [Python] Easy solution | python-easy-solution-by-arkumari2000-n9zi | \nclass Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n minDist = math.inf\n ans = -1\n for i | arkumari2000 | NORMAL | 2021-05-25T04:24:57.626273+00:00 | 2021-05-25T04:24:57.626360+00:00 | 5,416 | false | ```\nclass Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n minDist = math.inf\n ans = -1\n for i in range(len(points)):\n if points[i][0]==x or points[i][1]==y:\n manDist = abs(points[i][0]-x)+abs(points[i][1]-y)\n ... | 31 | 0 | ['Python', 'Python3'] | 5 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | javascript 100% 100% simple | javascript-100-100-simple-by-soley-gt4f | \nvar nearestValidPoint = function(x, y, points) {\n let min = Infinity\n let idx = -1\n points.forEach(([a,b], i)=>{\n if(a===x || b===y){\n | soley | NORMAL | 2021-03-07T13:27:03.683820+00:00 | 2021-03-07T13:27:03.683862+00:00 | 1,758 | false | ```\nvar nearestValidPoint = function(x, y, points) {\n let min = Infinity\n let idx = -1\n points.forEach(([a,b], i)=>{\n if(a===x || b===y){\n const dist = Math.abs(x-a) + Math.abs(y-b)\n if(dist<min){\n idx = i\n min = dist\n }\n }... | 27 | 0 | ['JavaScript'] | 3 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | [C++] Easy solution || 100% Time || 100% Space | c-easy-solution-100-time-100-space-by-_a-g9py | 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 | _A_Man | NORMAL | 2021-03-07T07:57:43.191303+00:00 | 2021-03-08T06:10:57.964098+00:00 | 2,508 | false | 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 ... | 14 | 0 | ['C', 'C++'] | 2 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | ✅ Easy C++ O(N) Soln. [ FAANG😱 Interview Optimized code ] | easy-c-on-soln-faang-interview-optimized-0ebt | 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 | AdityaBhate | NORMAL | 2022-11-03T11:57:45.675383+00:00 | 2022-11-03T11:59:33.788549+00:00 | 941 | false | `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... | 8 | 0 | ['Array', 'C', 'Python', 'C++', 'Java'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Python Beginners | 85% Fast | | python-beginners-85-fast-by-samarthbaron-bnf2 | Upvote if it helped. Thanks\n\n\nclass Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n min_dis= 10000 \n | SamarthBaronia | NORMAL | 2022-08-20T15:42:44.589257+00:00 | 2022-08-20T15:42:44.589292+00:00 | 1,214 | false | Upvote if it helped. Thanks\n\n```\nclass Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n min_dis= 10000 \n ind = -1\n for i in range (len (points)):\n if points[i][0] == x or points [i][1] == y:\n mandist = abs(points[i][0] -x... | 8 | 1 | ['Python'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | [C++] Linear Solution Explained, 100% Time, 100% Space | c-linear-solution-explained-100-time-100-qlir | Pleasant warm up - easy to understand and to execute.\n\nTo solve this problem, we will need 2 support variables first:\n res is where we will store the positio | Ajna2 | NORMAL | 2021-03-06T23:05:00.634342+00:00 | 2021-03-06T23:05:00.634375+00:00 | 1,262 | false | Pleasant warm up - easy to understand and to execute.\n\nTo solve this problem, we will need 2 support variables first:\n* `res` is where we will store the position of the first best fit we find, initially set to `-1` (which will then be returned when no match has been found);\n* `bestDist` will store the current close... | 8 | 0 | ['C', 'C++'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Java | easy to understand | java-easy-to-understand-by-venkat089-yujy | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Venkat089 | NORMAL | 2022-12-27T06:38:55.615527+00:00 | 2022-12-27T06:38:55.615567+00:00 | 1,011 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 7 | 0 | ['Java'] | 1 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Java. Arrays. Find Nearest Point That Has the Same X or Y Coordinate | java-arrays-find-nearest-point-that-has-0vbu0 | \n\nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n int minManh = Integer.MAX_VALUE;\n int indMin = -1;\n | red_planet | NORMAL | 2023-05-08T09:27:17.919420+00:00 | 2023-05-08T09:27:17.919451+00:00 | 624 | false | \n```\nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n int minManh = Integer.MAX_VALUE;\n int indMin = -1;\n for (int i = 0; i < points.length; i++)\n {\n int tmpManh = Math.abs(x - points[i][0]) + Math.abs(y - points[i][1]);\n if ((... | 6 | 0 | ['Array', 'Java'] | 1 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | python solution easy to understand O(n) , O(1) | python-solution-easy-to-understand-on-o1-r56c | Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n# Code\n\nclass Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[in | sintin1310 | NORMAL | 2022-11-25T09:10:59.153109+00:00 | 2022-11-25T09:10:59.153146+00:00 | 1,135 | false | # Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n# Code\n```\nclass Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n\n minn=float(\'inf\')\n index=-1\n for i , v in enumerate(points):\n if v[0]==x or v[1]==y:\n ... | 6 | 0 | ['Python3'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | 📌 Python3 simple naive approach | python3-simple-naive-approach-by-dark_wo-2xoo | \nclass Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n result = None\n maximumDistance = float("inf | dark_wolf_jss | NORMAL | 2022-07-01T03:41:42.107439+00:00 | 2022-07-01T03:41:42.107468+00:00 | 1,079 | false | ```\nclass Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n result = None\n maximumDistance = float("inf")\n \n for index,point in enumerate(points):\n a,b = point\n distance = abs(x-a) + abs(y-b)\n if distance < m... | 6 | 0 | ['Python3'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | SUPER-UGLY Python one-liner for those who are into this stuff :D | super-ugly-python-one-liner-for-those-wh-ojmu | \nclass Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n return min(map(lambda p:[abs(p[0] - x) + abs(p[1] - | qqzzqq | NORMAL | 2022-03-15T21:58:14.644709+00:00 | 2022-03-15T21:58:14.644763+00:00 | 564 | false | ```\nclass Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n return min(map(lambda p:[abs(p[0] - x) + abs(p[1] - y), p[2]], list(filter(lambda p:p[0] == x or p[1] == y, map(lambda l:l[1] + [l[0]], enumerate(points)))) or [[0,0,-1]]))[1]\n``` | 6 | 0 | ['Python'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Java | Simple | Explained | java-simple-explained-by-prashant404-il45 | T/S: O(n)/O(1), where n = size(points)\n\npublic int nearestValidPoint(int x, int y, int[][] points) {\n\tvar nearest = -1;\n\n\tfor (int i = 0, minDistance = I | prashant404 | NORMAL | 2022-01-31T02:17:00.304364+00:00 | 2022-01-31T02:17:00.304408+00:00 | 792 | false | **T/S:** O(n)/O(1), where n = size(points)\n```\npublic int nearestValidPoint(int x, int y, int[][] points) {\n\tvar nearest = -1;\n\n\tfor (int i = 0, minDistance = Integer.MAX_VALUE; i < points.length; i++)\n\t\tif (x == points[i][0] || y == points[i][1]) { // check valid point\n\t\t\tvar distance = Math.abs(x - poin... | 6 | 0 | ['Java'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Java || Easy to Understand || 1ms || beats 100% || O(points.length) | java-easy-to-understand-1ms-beats-100-op-icjf | \n // O(points.length) O(1)\n\tpublic int nearestValidPoint(int x, int y, int[][] points) {\n\n\t\tint min = Integer.MAX_VALUE, ans = -1, idx = -1;\n\t\tfor | LegendaryCoder | NORMAL | 2021-03-08T10:45:45.045591+00:00 | 2021-03-08T10:45:45.045628+00:00 | 1,379 | false | \n // O(points.length) O(1)\n\tpublic int nearestValidPoint(int x, int y, int[][] points) {\n\n\t\tint min = Integer.MAX_VALUE, ans = -1, idx = -1;\n\t\tfor (int[] point : points) {\n\t\t\tidx++;\n\t\t\tif (point[0] == x || point[1] == y) {\n\t\t\t\tint dist = distance(x, y, point[0], point[1]);\n\t\t\t\tif (dist < ... | 6 | 0 | [] | 1 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Python easy solution O(n) | python-easy-solution-on-by-it_bilim-uk7j | \ndef nearestValidPoint(self, x, y, p):\n ind = -1\n mn = 100000000000000\n for i in range(len(p)):\n if x == p[i][0] or y == p[ | it_bilim | NORMAL | 2021-03-06T16:57:32.957972+00:00 | 2021-03-06T16:58:28.266611+00:00 | 951 | false | ```\ndef nearestValidPoint(self, x, y, p):\n ind = -1\n mn = 100000000000000\n for i in range(len(p)):\n if x == p[i][0] or y == p[i][1]:\n t = abs(x - p[i][0]) + abs(y - p[i][1])\n if t < mn:\n mn, ind = t, i\n return ind\n``` | 6 | 3 | ['Python'] | 2 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | [JAVA]☕ | Easy and Explained Solution ❤ | Speed Beats 100% ✔️ | java-easy-and-explained-solution-speed-b-8s0e | Approach\n Describe your approach to solving the problem. \nThe solution involves a simple iteration of the array. \n\nAt each iteration we have to check if the | user0970Ja | NORMAL | 2023-03-06T19:30:44.451575+00:00 | 2023-03-06T19:30:44.451624+00:00 | 1,171 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nThe solution involves a simple **iteration of the array**. \n\n*At each iteration* we have to check if **the point is valid**, in this case we have to check if the distance of this point is shorter than the distance that we found in previous iteration... | 5 | 0 | ['Array', 'Java'] | 2 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | ✔💯 simple solution with explanation | simple-solution-with-explanation-by-atha-aiqz | \nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) \n {\n /* \n\t\tHere we are just iterating over the | atharva_kulkarni1 | NORMAL | 2022-11-28T18:01:02.985998+00:00 | 2022-11-28T18:05:43.750330+00:00 | 267 | false | ```\nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) \n {\n /* \n\t\tHere we are just iterating over the given array and if we get any \n\t\tvalid point (i.e. it shares either x-coordinate OR y-coordinate with\n\t\tour obtained points) and if the currDist is mo... | 5 | 0 | ['C', 'C++'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Easiest and Fastest Solution | easiest-and-fastest-solution-by-parulsah-i8a7 | Please Upvote (^_^)\n\nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] point) {\n int ans=Integer.MAX_VALUE;\n int var=-1 | parulsahni621 | NORMAL | 2022-09-26T16:32:11.074512+00:00 | 2022-09-26T16:32:11.074554+00:00 | 755 | false | Please Upvote (^_^)\n```\nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] point) {\n int ans=Integer.MAX_VALUE;\n int var=-1;\n for(int i=0;i<point.length;i++)\n {\n \n if(point[i][0]==x || point[i][1]==y)\n {\n int m=M... | 5 | 0 | [] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | JavaScript Solution Using a Map Object | javascript-solution-using-a-map-object-b-okzl | Found this solution helpful? Consider showing support by upvoting this post. If there are any questions, kindly leave a comment below. Thank you and happy hacki | sronin | NORMAL | 2022-06-22T02:34:20.674072+00:00 | 2022-07-23T23:10:29.701725+00:00 | 485 | false | Found this solution helpful? Consider showing support by upvoting this post. If there are any questions, kindly leave a comment below. Thank you and happy hacking!\n```\nvar nearestValidPoint = function (x, y, points) {\n let manhattanIndices = new Map()\n let currentMin = Infinity\n\n points.forEach((point, i... | 5 | 0 | ['JavaScript'] | 3 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Python - Clean and Simple! | python-clean-and-simple-by-domthedevelop-6kmy | Solution:\n\nclass Solution:\n def nearestValidPoint(self, x1, y1, points):\n minIdx, minDist = -1, inf\n for i,point in enumerate(points):\n | domthedeveloper | NORMAL | 2022-05-11T08:29:44.663358+00:00 | 2022-05-11T08:29:44.663403+00:00 | 1,212 | false | **Solution**:\n```\nclass Solution:\n def nearestValidPoint(self, x1, y1, points):\n minIdx, minDist = -1, inf\n for i,point in enumerate(points):\n x2, y2 = point\n if x1 == x2 or y1 == y2:\n dist = abs(x1-x2) + abs(y1-y2)\n if dist < minDist:\n ... | 5 | 0 | ['Array', 'Python', 'Python3'] | 1 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | [Ruby] O(n) | ruby-on-by-mistersky-y2fr | \n# @param {Integer} x\n# @param {Integer} y\n# @param {Integer[][]} points\n# @return {Integer}\ndef nearest_valid_point(x, y, points)\n distances = []\n \n | mistersky | NORMAL | 2021-03-07T08:30:41.179258+00:00 | 2021-03-07T08:30:41.179300+00:00 | 121 | false | ```\n# @param {Integer} x\n# @param {Integer} y\n# @param {Integer[][]} points\n# @return {Integer}\ndef nearest_valid_point(x, y, points)\n distances = []\n \n points.each_with_index do |point, index|\n a, b = point\n distances << [(x - a).abs + (y - b).abs, index] if a == x || b == y\n end\n \n return -1 ... | 5 | 0 | ['Ruby'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | C++ Solution | c-solution-by-pranto1209-w4bl | Code\n\nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n int ans = -1, mdis = INT_MAX;\n for(in | pranto1209 | NORMAL | 2022-12-24T05:46:54.989500+00:00 | 2023-03-24T10:57:39.498304+00:00 | 991 | false | # Code\n```\nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n int ans = -1, mdis = INT_MAX;\n for(int i=0; i<points.size(); i++) {\n if(points[i][0] == x or points[i][1] == y) {\n int dis = abs(points[i][0] - x) + abs(points[i][1... | 4 | 0 | ['C++'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | ✔️ explained solution | beats 90% in time | 95% in space | C++ | explained-solution-beats-90-in-time-95-i-xsra | We first check whether there are common coordinates between the given (x,y) & elements of the given array. If there is we compare it with the previous Manhattan | coding_menance | NORMAL | 2022-10-26T09:29:42.547552+00:00 | 2022-10-26T09:30:54.125106+00:00 | 1,701 | false | We first check whether there are common coordinates between the given (x,y) & elements of the given array. If there is we compare it with the previous **Manhattan distance** & if it is less we update the index to be returned to the current one [remember we are asked for the index of the point with smallest Manhattan di... | 4 | 0 | ['Array', 'C++'] | 2 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | C++ | c-by-easy0peasy1-oj0m | \nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n int n = points.size();\n int temp = INT_MAX; | easy0peasy1 | NORMAL | 2022-07-17T13:52:27.389711+00:00 | 2022-07-17T13:52:27.389752+00:00 | 344 | false | ```\nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n int n = points.size();\n int temp = INT_MAX;\n int distance;\n int ans = INT_MIN;\n for(int i = 0; i < n; i++) {\n if(points[i][0] == x || points[i][1] == y) {\n ... | 4 | 0 | ['C'] | 1 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | easily understandable code | easily-understandable-code-by-saswata_ra-eias | \nclass Solution(object):\n def nearestValidPoint(self, x, y, points):\n """\n :type x: int\n :type y: int\n :type points: List[L | Saswata_Rakshit | NORMAL | 2022-03-12T17:19:34.147319+00:00 | 2022-03-12T17:19:34.147364+00:00 | 296 | false | ```\nclass Solution(object):\n def nearestValidPoint(self, x, y, points):\n """\n :type x: int\n :type y: int\n :type points: List[List[int]]\n :rtype: int\n """\n \n \n mdist=float(\'inf\')#assigning a large value to the manhattan distance\n inde... | 4 | 0 | ['Python'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | [python] - easy to understand | python-easy-to-understand-by-sergimia-buyk | Iterating through the all points with enumerate(points) that returns index (i) and value (point)\nIf the current candidate (point) don\'t have either same X ax | SergiMia | NORMAL | 2021-03-06T16:05:02.238658+00:00 | 2021-03-06T16:32:19.027336+00:00 | 269 | false | Iterating through the all points with `enumerate(points)` that returns index (i) and value (point)\nIf the current candidate (point) don\'t have either same X axis or Y axis - skip it and go to the next one. Continue inside the loop only if current point is "valid".\nCalculate smallest distance (dist) by comparing to ... | 4 | 2 | [] | 1 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Python3 Easiest and Most understandable solution | python3-easiest-and-most-understandable-qyy3o | The solution has three parts, \n1. Checking the validity of the given points.\n2. Finding the smallest Manhattan distance \n3. returning the index of the smalle | nehanayak | NORMAL | 2023-01-10T18:03:51.562154+00:00 | 2023-01-10T18:03:51.562196+00:00 | 2,028 | false | The solution has three parts, \n1. Checking the validity of the given points.\n2. Finding the smallest Manhattan distance \n3. returning the index of the smallest Manhattan distance \n\nWe check if there are no valid points and return -1\n\n# Code\n```\nclass Solution:\n def nearestValidPoint(self, x: int, y: int, p... | 3 | 0 | ['Python3'] | 2 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | c++ | easy | short | c-easy-short-by-venomhighs7-q5m3 | \n# Code\n\nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n int ind = -1;\n int dist = INT_MAX; | venomhighs7 | NORMAL | 2022-10-12T03:29:34.349488+00:00 | 2022-10-12T03:29:34.349528+00:00 | 770 | false | \n# Code\n```\nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n int ind = -1;\n int dist = INT_MAX; \n for(int i =0; i<points.size(); i++){\n if(points[i][0] == x || points[i][1] == y){\n int temp = abs(x-points[i][0])+abs(... | 3 | 0 | ['C++'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | C++ || Brute Force approach || Easy to Understand | c-brute-force-approach-easy-to-understan-ppk8 | \nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n int mi=INT_MAX,res=-1;\n for(int i=0;i<point | srikrishna0874 | NORMAL | 2022-09-19T12:54:55.737234+00:00 | 2022-09-19T12:54:55.737274+00:00 | 51 | false | ```\nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n int mi=INT_MAX,res=-1;\n for(int i=0;i<points.size();i++)\n {\n int x1=points[i][0],y1=points[i][1];\n if(x==x1||y==y1) \n {\n int dis=abs(x1-x)+a... | 3 | 0 | ['C'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | [JS] Easy greedy O(n) solution | js-easy-greedy-on-solution-by-hugotannus-nxvx | \nvar nearestValidPoint = function(x, y, points) {\n let distance = 99999, validIndex = -1;\n \n for(let i in points) {\n const [a, b] = points[ | hugotannus | NORMAL | 2022-08-17T00:16:11.466744+00:00 | 2022-08-17T00:17:43.042471+00:00 | 257 | false | ```\nvar nearestValidPoint = function(x, y, points) {\n let distance = 99999, validIndex = -1;\n \n for(let i in points) {\n const [a, b] = points[i];\n if(a != x && b != y) continue;\n \n let manhattan = Math.abs(x-a) || Math.abs(y-b);\n \n // It is not necessary to c... | 3 | 0 | ['Greedy', 'JavaScript'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | [JAVA] simple and easy solution | java-simple-and-easy-solution-by-juganta-i8cm | \nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n var nearest = - 1;\n\n\tfor (int i = 0, minDistance = Integer.MAX_V | Jugantar2020 | NORMAL | 2022-08-14T06:30:50.523483+00:00 | 2022-08-14T06:30:50.523523+00:00 | 218 | false | ```\nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n var nearest = - 1;\n\n\tfor (int i = 0, minDistance = Integer.MAX_VALUE; i < points.length; i ++)\n\t\tif (x == points[i][0] || y == points[i][1]) { // check valid point\n\t\t\tvar distance = Math.abs(x - points[i][0]) + Mat... | 3 | 0 | ['Array', 'Java'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Easy JavaScript Solution | easy-javascript-solution-by-azensky-o65k | \nvar nearestValidPoint = function(x, y, points) {\n let minDist = Infinity;\n let res;\n \n for (let i = 0; i < points.length; i++) {\n let | AZensky | NORMAL | 2022-08-04T21:04:07.137690+00:00 | 2022-08-04T21:04:07.137724+00:00 | 389 | false | ```\nvar nearestValidPoint = function(x, y, points) {\n let minDist = Infinity;\n let res;\n \n for (let i = 0; i < points.length; i++) {\n let [currX, currY] = points[i];\n \n if (currX === x || currY === y) {\n let dist = Math.abs(x - currX) + Math.abs(y - currY);\n ... | 3 | 0 | ['JavaScript'] | 1 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | SSS: Simple Swift Solution ★★ | sss-simple-swift-solution-by-mishe1e-h8ap | \nfunc nearestValidPoint(_ x: Int, _ y: Int, _ points: [[Int]]) -> Int {\n\tvar (result, dMin) = (-1, Int.max)\n\n\tfor (i, point) in points.enumerated() {\n\t\ | mishe1e | NORMAL | 2022-04-28T06:20:24.886110+00:00 | 2022-12-09T04:54:24.652267+00:00 | 139 | false | ```\nfunc nearestValidPoint(_ x: Int, _ y: Int, _ points: [[Int]]) -> Int {\n\tvar (result, dMin) = (-1, Int.max)\n\n\tfor (i, point) in points.enumerated() {\n\t\tlet x1 = point[0], y1 = point[1]\n\t\tguard x == x1 || y == y1 else { continue }\n\t\tlet d = abs(x - x1) + abs( y - y1)\n\t\tif d < dMin {\n\t\t\tdMin = d\... | 3 | 0 | ['Swift'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Simple python solution | simple-python-solution-by-arizala13-zouf | ```\nclass Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n # answer array to insrt the index\n answe | arizala13 | NORMAL | 2022-04-23T19:30:01.171836+00:00 | 2022-04-23T19:30:01.171878+00:00 | 281 | false | ```\nclass Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n # answer array to insrt the index\n answer = -1\n # starting point for distance to compare\n man_distance = float("inf")\n \n # allows east insert to answer arrow and increm... | 3 | 0 | ['Python'] | 2 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Java || faster than 100% || Simple solution | java-faster-than-100-simple-solution-by-nn8rx | \nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n int min = Integer.MAX_VALUE;\n int index = -1;\n for | funingteng | NORMAL | 2022-03-30T14:36:26.834799+00:00 | 2022-03-30T14:36:26.834824+00:00 | 305 | false | ```\nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n int min = Integer.MAX_VALUE;\n int index = -1;\n for (int i = 0; i < points.length; i++) {\n int[] point = points[i];\n if (point[0] == x) {\n int d = Math.abs(y - point[1]... | 3 | 0 | ['Java'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | ✅[Python] Simple Solution | python-simple-solution-by-iamprateek-vluw | \ndef nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n ans = -1\n n = len(points)\n mini = float(inf)\n \n | iamprateek | NORMAL | 2022-03-05T18:06:00.136265+00:00 | 2022-03-05T18:06:00.136306+00:00 | 236 | false | ```\ndef nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n ans = -1\n n = len(points)\n mini = float(inf)\n \n for i in range(n):\n if points[i][0]==x or points[i][1]==y:\n dis = abs(points[i][0]-x) + abs(points[i][1]-y)\n ... | 3 | 0 | ['Python3'] | 1 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Python clean solution | python-clean-solution-by-shimkoaa-kun2 | \nclass Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n def compute_dist(x1, y1, x2, y2):\n retu | shimkoaa | NORMAL | 2022-03-04T07:37:49.657956+00:00 | 2022-03-04T07:37:49.658003+00:00 | 180 | false | ```\nclass Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n def compute_dist(x1, y1, x2, y2):\n return abs(x1-x2) + abs(y1-y2)\n \n min_idx, min_dist = -1, float(\'inf\')\n \n for i, (x_hat, y_hat) in enumerate(points):\n ... | 3 | 0 | [] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Easy to understand JavaScript solution (reduce) | easy-to-understand-javascript-solution-r-8htm | \tvar nearestValidPoint = function(x, y, points) {\n\t\tconst valid = points.reduce((acc, [pointX, pointY], index) => {\n\t\t\tif (x === pointX || y === pointY) | tzuyi0817 | NORMAL | 2021-08-21T05:52:40.811648+00:00 | 2021-08-21T05:52:40.811680+00:00 | 211 | false | \tvar nearestValidPoint = function(x, y, points) {\n\t\tconst valid = points.reduce((acc, [pointX, pointY], index) => {\n\t\t\tif (x === pointX || y === pointY) {\n\t\t\t\tconst distance = Math.abs(x - pointX) + Math.abs(y - pointY);\n\n\t\t\t\tdistance < acc.distance && (acc = { distance, index });\n\t\t\t}\n\t\t\tret... | 3 | 0 | ['JavaScript'] | 1 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Elegant Python, C++ | elegant-python-c-by-aragorn-15wj | Python\n\nclass Solution:\n def nearestValidPoint(self, x, y, points):\n best = 100000\n where = -1\n \n for i,ab in enumerate(p | aragorn_ | NORMAL | 2021-03-14T22:02:40.910509+00:00 | 2021-06-02T15:48:33.921713+00:00 | 263 | false | **Python**\n```\nclass Solution:\n def nearestValidPoint(self, x, y, points):\n best = 100000\n where = -1\n \n for i,ab in enumerate(points):\n a,b = ab\n if a==x or b==y:\n d = abs(x-a) + abs(y-b)\n if d<best:\n bes... | 3 | 1 | ['C', 'Python', 'Python3'] | 2 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Check all points - O(n) time and O(1) space JavaScript solution | check-all-points-on-time-and-o1-space-ja-tuk1 | This is staraightforward problem, example implementation in JavaScript:\n\n\nvar nearestValidPoint = function(x, y, points) {\n // keep track of both the sho | user4125zi | NORMAL | 2021-03-06T16:13:15.227726+00:00 | 2021-03-06T16:13:15.227775+00:00 | 256 | false | This is staraightforward problem, example implementation in JavaScript:\n\n```\nvar nearestValidPoint = function(x, y, points) {\n // keep track of both the shortest distance and its index\n let ans = -1, ansDist = Number.MAX_SAFE_INTEGER;\n \n for (let i = 0; i < points.length; i++) {\n const [px, p... | 3 | 0 | ['JavaScript'] | 1 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | C++ | very easy | c-very-easy-by-sonusharmahbllhb-w5wb | \nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n int dist=INT_MAX;int ans=-1;\n for(int i=0;i | sonusharmahbllhb | NORMAL | 2021-03-06T16:02:54.238435+00:00 | 2021-03-06T16:02:54.238462+00:00 | 309 | false | ```\nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n int dist=INT_MAX;int ans=-1;\n for(int i=0;i<points.size();i++)\n {\n if(points[i][0]==x or points[i][1]==y)\n {\n int mh=abs(x-points[i][0])+abs(points[i][1... | 3 | 2 | ['C', 'C++'] | 1 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Easy Solution🔥🔥O(N) Solution ; Detailed Explanation✌️✌️ | easy-solutionon-solution-detailed-explan-1kao | Intuition\n Describe your first thoughts on how to solve this problem. \nHere, we simply need to check if the point is valid with the minimum Manhattan distance | anshika_coder467 | NORMAL | 2024-06-20T08:51:25.372951+00:00 | 2024-06-20T08:51:25.372991+00:00 | 335 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nHere, we simply need to check if the point is valid with the minimum **Manhattan distance** and return the index of it else return -1.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nHere the current location is gi... | 2 | 0 | ['C++'] | 1 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | 🦚 | 100% beaten golang solution | self-explanatory | 100-beaten-golang-solution-self-explanat-92s8 | Code\n\nfunc nearestValidPoint(x int, y int, points [][]int) int {\n mn := 10000\n ans := -1\n for ind, point := range points {\n if point[0] == | makarkananov | NORMAL | 2024-01-08T22:58:37.244024+00:00 | 2024-01-08T22:58:37.244073+00:00 | 40 | false | # Code\n```\nfunc nearestValidPoint(x int, y int, points [][]int) int {\n mn := 10000\n ans := -1\n for ind, point := range points {\n if point[0] == x || point[1] == y{\n if mn >int(math.Abs(float64(x - point[0])) + math.Abs(float64(y - point[1]))) {\n mn = int(math.Abs(float6... | 2 | 0 | ['Go'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Find the Nearest Valid Point to a Given Coordinate | find-the-nearest-valid-point-to-a-given-xdl9z | Intuition\n Describe your first thoughts on how to solve this problem. \nWe need to find the index of the point in the given array that is closest to the given | RaimberdiyevB | NORMAL | 2023-04-29T15:41:15.766092+00:00 | 2023-04-29T15:41:15.766147+00:00 | 170 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe need to find the index of the point in the given array that is closest to the given (x, y) coordinate and has either the same x or y coordinate as the given coordinate.\n\n# Approach\n<!-- Describe your approach to solving the problem.... | 2 | 0 | ['Array', 'Java'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | ✅ Best and Easy solution 100% ✅ | best-and-easy-solution-100-by-amitmungar-ynii | \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 | amitmungare27 | NORMAL | 2023-04-01T09:43:55.017769+00:00 | 2023-04-01T09:43:55.017811+00:00 | 1,170 | false | \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 ... | 2 | 0 | ['Array', 'Java'] | 1 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | ✅ 🔥 One line Python || ⚡very easy solution | one-line-python-very-easy-solution-by-ma-11sn | \n\nclass Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n return min([(abs(p[0]-x)+abs(p[1]-y), i) for i, p | maary_ | NORMAL | 2023-03-16T17:33:03.867113+00:00 | 2023-03-16T17:33:03.867162+00:00 | 97 | false | \n```\nclass Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n return min([(abs(p[0]-x)+abs(p[1]-y), i) for i, p in enumerate(points) if p[0]==x or p[1]==y], default=(-1, -1))[1]\n\n``` | 2 | 0 | ['Python', 'Python3', 'Python ML'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | 🔥 C++ || Beats 99.60% || O(n) time, O(1) space || Easy to understand 🔥 | c-beats-9960-on-time-o1-space-easy-to-un-a0ih | Intuition\n\n\n# Approach\nWe check for each point the coincidence of at least one of the coordinates. If there is a match, then we calculate the distance to th | frixinglife | NORMAL | 2023-01-12T10:20:23.956967+00:00 | 2023-01-15T10:03:36.893534+00:00 | 793 | false | # Intuition\n\n\n# Approach\nWe check for each point **the coincidence of at least one of the coordinates**. If there is a match, then we **calculate the distance to the original point**. If **the distance*... | 2 | 0 | ['C++'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | easy c++ approach | easy-c-approach-by-sahildudi-i7rv | \n# Complexity\n- Time complexity:\no(n)\n\n\n\n# Code\n\nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n | SahilDudi | NORMAL | 2022-12-19T07:50:55.035720+00:00 | 2022-12-19T07:50:55.035762+00:00 | 498 | false | \n# Complexity\n- Time complexity:\no(n)\n\n\n\n# Code\n```\nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n int mindis=INT_MAX;\n int ans=-1;\n for(int i=0;i<points.size();i++){\n if(points[i][0]==x || points[i][1]==y){\n ... | 2 | 0 | ['C++'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Easy C++ Solution ✔ | easy-c-solution-by-akanksha984-9ypn | Here is my C++ Solution :-\n\nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n int val= -1; int v= INT | akanksha984 | NORMAL | 2022-11-20T15:53:58.281154+00:00 | 2022-11-20T15:53:58.281195+00:00 | 656 | false | Here is my C++ Solution :-\n```\nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n int val= -1; int v= INT_MAX;\n for (int i=0; i<points.size(); i++){\n if (x!=points[i][0] && y!= points[i][1])continue;\n if (v > (abs(points[i][0]-x)+... | 2 | 0 | ['Array', 'Math', 'C', 'C++'] | 1 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Java | 2 Solutions | java-2-solutions-by-tbekpro-mpwn | Solution 1 | 13 ms\n\nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n int result = -1, min = Integer.MAX_VALUE;\n | tbekpro | NORMAL | 2022-11-02T04:34:16.521863+00:00 | 2022-11-02T04:34:16.521906+00:00 | 619 | false | # Solution 1 | 13 ms\n```\nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n int result = -1, min = Integer.MAX_VALUE;\n for (int i = 0; i < points.length; i++) {\n if (x == points[i][0] || y == points[i][1]) {\n int manh = Math.abs(x - points[i... | 2 | 0 | ['Java'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Simple Java Solution | simple-java-solution-by-abhi1234689-jjmm | \n\n# Code\n\nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n\n int min = Integer.MAX_VALUE,index=-1;\n for(i | abhi1234689 | NORMAL | 2022-10-24T17:27:44.499893+00:00 | 2022-10-24T17:27:44.499926+00:00 | 368 | false | \n\n# Code\n```\nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n\n int min = Integer.MAX_VALUE,index=-1;\n for(int i=0;i<points.length;i++){\n int dist = Math.abs(points[i][0]-x) + Math.abs(points[i][1]-y);\n if((points[i][0] == x || points[i][1] ... | 2 | 0 | ['Java'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | C++ Solution for beginners | c-solution-for-beginners-by-akshat0610-3fa8 | \nclass Solution {\npublic:\n int nearestValidPoint(int x1, int y1, vector<vector<int>>& arr) {\n \n int ans_dis=INT_MAX;\n int ans_idx= | akshat0610 | NORMAL | 2022-10-01T14:33:03.672270+00:00 | 2022-10-01T14:33:03.672305+00:00 | 506 | false | ```\nclass Solution {\npublic:\n int nearestValidPoint(int x1, int y1, vector<vector<int>>& arr) {\n \n int ans_dis=INT_MAX;\n int ans_idx=-1;\n\n for(int i=0;i<arr.size();i++)\n {\n int x2=arr[i][0];\n int y2=arr[i][1];\n\n if(x1==x2 or y1==y2)\n ... | 2 | 0 | ['Array', 'C', 'C++'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | C++ Solution for beginners | c-solution-for-beginners-by-nehagupta_09-e7q7 | \nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n int ans=-1;\n int dis;\n int min_dis= | NehaGupta_09 | NORMAL | 2022-10-01T14:26:41.397182+00:00 | 2022-10-01T14:26:41.397222+00:00 | 771 | false | ```\nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n int ans=-1;\n int dis;\n int min_dis=INT_MAX;\n for(int i=0;i<points.size();i++)\n {\n if(points[i][0]==x or points[i][1]==y)\n {\n dis=abs(x-p... | 2 | 0 | ['C', 'C++'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Java | Math | Array | Easy Solution | java-math-array-easy-solution-by-divyans-8e27 | \nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n int min = Integer.MAX_VALUE,index=0;\n for(int i=0;i<points | Divyansh__26 | NORMAL | 2022-09-14T09:54:00.541595+00:00 | 2022-09-14T09:54:00.541634+00:00 | 116 | false | ```\nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n int min = Integer.MAX_VALUE,index=0;\n for(int i=0;i<points.length;i++){\n int x1 = points[i][0];\n int y1 = points[i][1];\n if(x==x1 || y==y1){\n if(Math.abs(x-x1)+Mat... | 2 | 0 | ['Array', 'Math', 'Java'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | JAVA | EASY CODE 3ms Solution | java-easy-code-3ms-solution-by-fardeensh-8kqa | \n int min=Integer.MAX_VALUE;\n int index=-1;\n int dist=0;\n for(int i=0;i<points.length;i++){\n if(points[i][0]==x||poi | fardeenshaik927 | NORMAL | 2022-08-20T19:52:31.650425+00:00 | 2022-08-20T19:53:09.811646+00:00 | 62 | false | \n int min=Integer.MAX_VALUE;\n int index=-1;\n int dist=0;\n for(int i=0;i<points.length;i++){\n if(points[i][0]==x||points[i][1]==y){\n dist = Math.abs(points[i][0]-x) + Math.abs(points[i][1]-y);\n if(dist<min){\n min=dist;\n ... | 2 | 0 | [] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | [JAVA] || goto approach, simple and explained | java-goto-approach-simple-and-explained-447pr | Algorithm explained\nTo keep the runtime low we check for valid points and the closest one in a single run through (loop).\n\n\nclass Solution {\n public int | Arcta | NORMAL | 2022-08-15T12:35:37.243643+00:00 | 2022-08-15T12:35:37.243669+00:00 | 101 | false | **Algorithm explained**\nTo keep the runtime low we check for valid points and the closest one in a single run through (loop).\n\n```\nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n\n int minDist=Integer.MAX_VALUE; //the variable to keep track of the minimal distance so fa... | 2 | 0 | ['Java'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Python || Easy solution | python-easy-solution-by-e_stanulevich-e38v | ```\nind = -1\ndist = float(\'inf\')\n \nfor i, point in enumerate(points):\n\tif (x == point[0] or y == point[1]):\n\t\td = abs(x-point[0]) + abs(y-point | e_stanulevich | NORMAL | 2022-07-30T17:56:12.206055+00:00 | 2022-07-30T17:56:12.206101+00:00 | 217 | false | ```\nind = -1\ndist = float(\'inf\')\n \nfor i, point in enumerate(points):\n\tif (x == point[0] or y == point[1]):\n\t\td = abs(x-point[0]) + abs(y-point[1])\n if d < dist:\n\t\t\tdist = d\n ind = i\n \n\t\tif dist == 0:\n\t\t\tbreak\n \nreturn ind\n | 2 | 0 | ['Python'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Kotlin Fast and Easy Solution || 488ms, faster than 92.59% | kotlin-fast-and-easy-solution-488ms-fast-65hd | \nclass Solution {\n fun nearestValidPoint(x: Int, y: Int, points: Array<IntArray>): Int {\n var min = Int.MAX_VALUE\n var index = -1\n | Z3ROsum | NORMAL | 2022-07-19T01:32:33.250395+00:00 | 2022-07-19T01:32:33.250423+00:00 | 95 | false | ```\nclass Solution {\n fun nearestValidPoint(x: Int, y: Int, points: Array<IntArray>): Int {\n var min = Int.MAX_VALUE\n var index = -1\n for (ix in points.indices) {\n val i = points[ix]\n if (i[0] != x && i[1] != y) continue // the point is not "valid"\n val d... | 2 | 0 | ['Kotlin'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Go one pass easy hehe | go-one-pass-easy-hehe-by-tuanbieber-u0df | \nfunc nearestValidPoint(x int, y int, points [][]int) int {\n var res int = -1\n \n smallestDistance := 1 << 63 - 1\n \n for i := 0; i < len(poi | tuanbieber | NORMAL | 2022-06-28T03:43:16.382219+00:00 | 2022-06-28T03:43:16.382249+00:00 | 232 | false | ```\nfunc nearestValidPoint(x int, y int, points [][]int) int {\n var res int = -1\n \n smallestDistance := 1 << 63 - 1\n \n for i := 0; i < len(points); i++ {\n if points[i][0] == x || points[i][1] == y {\n if distance([]int{x, y}, points[i]) < smallestDistance {\n small... | 2 | 0 | ['C', 'Python', 'Java', 'Go'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Simple Java Solution | simple-java-solution-by-kashish905-d8xm | \nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n int smallest = Integer.MAX_VALUE ;\n int k = -1;\n | Kashish905 | NORMAL | 2022-06-16T09:14:24.784157+00:00 | 2022-06-16T09:14:24.784184+00:00 | 83 | false | ```\nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n int smallest = Integer.MAX_VALUE ;\n int k = -1;\n for(int i = 0;i<points.length;i++){\n if(points[i][0]==x || points[i][1]==y ){\n if( Math.abs((points[i][0]-x)) + Math.abs((points... | 2 | 0 | ['Java'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Find Nearest Point that same X or y coordinate | O(n) | find-nearest-point-that-same-x-or-y-coor-uoyb | I know this Looks so long but bare with me You will understand it thoroughly.\n\n\nclass Solution {\n \nprivate:\n int x1=0,y1=0; // To Store give x and y | babasaheb256 | NORMAL | 2022-05-27T07:59:08.525216+00:00 | 2022-05-27T07:59:38.973376+00:00 | 155 | false | I know this Looks so long but bare with me You will understand it thoroughly.\n```\n\nclass Solution {\n \nprivate:\n int x1=0,y1=0; // To Store give x and y val at start (to decrease manHatDis function memory footprint)\n // So that when calling function multiple time we did n\'t need to pass x... | 2 | 0 | ['C', 'C++'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Python - Pretty Brute Forceish but easy to understand | python-pretty-brute-forceish-but-easy-to-kev9 | \nclass Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n valid_pair = [] | derrjohn | NORMAL | 2022-04-29T06:15:11.560562+00:00 | 2022-04-29T06:15:11.560589+00:00 | 244 | false | ```\nclass Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n valid_pair = [] #Initializing an empty array\n distance_holder = (9999,9999) #creating default values for distance holder \n\n ... | 2 | 0 | ['Python', 'Python3'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Easy to understand - Python 3 | easy-to-understand-python-3-by-ankit_100-0ywp | class Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n \n min_d=1000000\n i=0\n ans=-1\ | ankit_100 | NORMAL | 2022-03-24T06:16:37.937921+00:00 | 2022-03-24T06:16:37.937957+00:00 | 76 | false | class Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n \n min_d=1000000\n i=0\n ans=-1\n for point in points:\n if x==point[0] or y == point[1]:\n mah = abs(x-point[0]) + abs(y-point[1])\n if mah<min... | 2 | 0 | [] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Python3 memory usage less than 94.85% | python3-memory-usage-less-than-9485-by-e-rihf | ```\nclass Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n ind = -1\n man = -1\n for i in poi | elefant1805 | NORMAL | 2022-03-15T12:29:53.831386+00:00 | 2022-03-15T12:29:53.831413+00:00 | 300 | false | ```\nclass Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n ind = -1\n man = -1\n for i in points:\n if i[0] == x or i[1] == y:\n if man == -1 or (abs(i[0] - x) + abs(i[1] - y)) < man:\n man = abs(i[0] - x) + ... | 2 | 0 | ['Python3'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Python Easy and Small Solution | python-easy-and-small-solution-by-imprad-9fi7 | ```\nclass Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n \n li=[i for i in points if i[0]==x or i[ | imPradhyumn | NORMAL | 2022-03-09T17:19:20.024519+00:00 | 2022-03-09T17:19:20.024561+00:00 | 194 | false | ```\nclass Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:\n \n li=[i for i in points if i[0]==x or i[1]==y] #chosse points where x or y is same\n if(len(li)==0): \n return -1\n ans=0\n mn=float(\'inf\') #it is same as in c... | 2 | 0 | ['Python'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | C++ | O(n) Time complexity | FASTER THAN 96.04% | c-on-time-complexity-faster-than-9604-by-v5rc | \nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n int minimum_manhattan = INT_MAX;\n int index | karnaa | NORMAL | 2022-03-03T11:21:13.692018+00:00 | 2022-03-03T11:21:13.692051+00:00 | 160 | false | ```\nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n int minimum_manhattan = INT_MAX;\n int index = -1;\n for (int i = 0; i < points.size(); i++) {\n if(points[i][0] == x || points[i][1] == y) {\n int manhattan = abs(poin... | 2 | 0 | ['C'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Python O(N) time O(1) space | python-on-time-o1-space-by-nybblr-57cq | python\nclass Solution:\n\t"""\n\tIn this problem we will simply iterate over all the points and keep track of the point \n\twith the lowest Manhattan distance. | nybblr | NORMAL | 2021-08-26T01:56:33.440169+00:00 | 2021-08-26T01:56:33.440222+00:00 | 189 | false | ```python\nclass Solution:\n\t"""\n\tIn this problem we will simply iterate over all the points and keep track of the point \n\twith the lowest Manhattan distance. We only perform this check if either x,y of the point\n\tmatches our current x,y from the function.\n\t"""\n def getManhattanDistance(self, point1: [int]... | 2 | 0 | ['Python'] | 1 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Simple JAVA 2MS answer | simple-java-2ms-answer-by-ranjan_1997-lvdq | \nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n int result = -1;\n int distance = Integer.MAX_VALUE;\n | ranjan_1997 | NORMAL | 2021-07-26T05:49:47.725764+00:00 | 2021-07-26T05:49:47.725810+00:00 | 147 | false | ```\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 ... | 2 | 0 | [] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Javascript one-line | javascript-one-line-by-saynn-f0cm | \n/**\n * @param {number} x\n * @param {number} y\n * @param {number[][]} points\n * @return {number}\n */\nvar nearestValidPoint = function(x, y, points) {\n | saynn | NORMAL | 2021-04-04T11:52:50.069715+00:00 | 2021-04-04T11:52:50.069745+00:00 | 214 | false | ```\n/**\n * @param {number} x\n * @param {number} y\n * @param {number[][]} points\n * @return {number}\n */\nvar nearestValidPoint = function(x, y, points) {\n return points.findIndex(p => p === points.filter(p => p[0] === x || p[1] === y)\n .sort((a,b) => -Math.abs(b[1]-y + b[0]-x) + Ma... | 2 | 0 | ['JavaScript'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Java PriorityQueue :) | java-priorityqueue-by-rrosy2000-ubz2 | \nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n \n //If the distance is same then sort using index else dis | rrosy2000 | NORMAL | 2021-03-27T12:24:59.795218+00:00 | 2021-03-27T12:24:59.795248+00:00 | 98 | false | ```\nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n \n //If the distance is same then sort using index else distance;\n PriorityQueue<int[]> pq = new PriorityQueue<>((a,b) -> a[1]==b[1] ? a[0]-b[0] : a[1]-b[1]);\n \n for(int i=0;i<points.length;i+... | 2 | 0 | [] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | C# | c-by-replicant-092v | One pass O(N)\n\npublic class Solution\n{\n public int NearestValidPoint(int x, int y, int[][] points)\n {\n int minIdx = -1;\n int minDista | replicant | NORMAL | 2021-03-08T08:35:03.636799+00:00 | 2021-03-08T08:35:03.636834+00:00 | 128 | false | One pass O(N)\n```\npublic class Solution\n{\n public int NearestValidPoint(int x, int y, int[][] points)\n {\n int minIdx = -1;\n int minDistance = int.MaxValue;\n for (int i = 0; i < points.Length; ++i)\n {\n var point = points[i];\n int distance;\n /... | 2 | 0 | [] | 1 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | 100% easy beat || O(N) sol. || beginner friendly sol. || | 100-easy-beat-on-sol-beginner-friendly-s-zzfs | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | iitian_010u | NORMAL | 2025-03-05T10:50:10.864959+00:00 | 2025-03-05T10:50:10.864959+00:00 | 160 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 1 | 0 | ['Array', 'Python', 'C++', 'Python3'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Python 3 🐍 || Beats 100% 🚀 || Easy 🔥 | python-3-beats-100-easy-by-rudraksh25-jngw | IntuitionThe problem requires finding the closest valid point that shares either the same x or y coordinate with our current location. Since Manhattan distance | Rudraksh25 | NORMAL | 2025-02-09T08:46:32.437226+00:00 | 2025-02-09T08:46:32.437226+00:00 | 119 | false | 
# Intuition
The problem requires finding the closest valid point that shares either the same x or y coordinate with our current location. Since Manhattan distance is simply the sum of absolute diff... | 1 | 0 | ['Python3'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | O(n) 🤩 🔥 | on-by-varuntyagig-7uom | Complexity
Time complexity:
O(n)
Space complexity:
O(1)
Code | varuntyagig | NORMAL | 2025-01-26T10:35:55.321381+00:00 | 2025-01-26T10:35:55.321381+00:00 | 60 | false | 
# Complexity
- Time complexity:
$$O(n)$$
- Space complexity:
$$O(1)$$
# Code
```cpp []
class Solution {
public:
int nearestValidPoint(int x, int y, vector<vector<int>>&... | 1 | 0 | ['Array', 'Math', 'C++'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | ☑️ Finding Nearest Point That Has the Same X or Y Coordinate. ☑️ | finding-nearest-point-that-has-the-same-8z100 | Code | Abdusalom_16 | NORMAL | 2024-12-23T05:34:27.075631+00:00 | 2024-12-23T05:34:27.075631+00:00 | 38 | false | # Code
```dart []
class Solution {
int nearestValidPoint(int x, int y, List<List<int>> points) {
List<int> distances = [];
for(int i = 0; i < points.length; i++){
if(points[i][0] == x || points[i][1] == y){
distances.add((x-points[i][0]).abs() + (y-points[i][1]).abs());
}
}
... | 1 | 0 | ['Array', 'Dart'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | long turn leke short turn aayi ismein ho gya wahi imp bas :D | long-turn-leke-short-turn-aayi-ismein-ho-5n2p | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | yesyesem | NORMAL | 2024-09-05T10:43:25.712717+00:00 | 2024-09-05T10:43:25.712747+00:00 | 13 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['C++'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Easy Solution Beats 100% | easy-solution-beats-100-by-vasu15-n46e | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Vasu15 | NORMAL | 2024-06-28T07:17:12.072359+00:00 | 2024-06-28T07:17:12.072409+00:00 | 240 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Java'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Beats 100%🔥JAVA | Brute Force | beats-100java-brute-force-by-sumo25-bsxy | \n\n# Approach\n Describe your approach to solving the problem. \nBrute Force\n\n# Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n | sumo25 | NORMAL | 2024-02-16T09:52:15.051478+00:00 | 2024-02-16T09:52:15.051513+00:00 | 186 | false | \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nBrute Force\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public int neares... | 1 | 0 | ['Java'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Simple java code 2 ms beats 99 % && 49 mb beats 84 % | simple-java-code-2-ms-beats-99-49-mb-bea-gd2k | \n# Complexity\n-\n\n# Code\n\nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n int ind=-1;\n int min=10001;\n | Arobh | NORMAL | 2024-01-14T04:54:14.147715+00:00 | 2024-01-14T04:54:14.147738+00:00 | 1 | false | \n# Complexity\n-\n\n# Code\n```\nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n int ind=-1;\n int min=10001;\n for(int i=0;i<points.length;i++) {\... | 1 | 0 | ['Java'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Find Nearest Point That Has the Same X or Y Coordinate | find-nearest-point-that-has-the-same-x-o-4ea5 | \n\n# Code\n\nclass Solution {\n public static class Points implements Comparable<Points>{\n int x,y,d,i;\n public Points(int x,int y,int d,int | riya1202 | NORMAL | 2023-10-24T09:29:37.420182+00:00 | 2023-10-24T09:29:37.420205+00:00 | 607 | false | \n\n# Code\n```\nclass Solution {\n public static class Points implements Comparable<Points>{\n int x,y,d,i;\n public Points(int x,int y,int d,int i){\n this.x=x;\n this.y=y;\n this.d=d;\n this.i=i;\n }\n public int compareTo(Points p2){\n ... | 1 | 0 | ['Array', 'Java'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Easy C++ solution || Beginner-friendly | easy-c-solution-beginner-friendly-by-pra-lh99 | \n\n# Code\n\nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n int ans=-1, min=INT_MAX;\n for(i | prathams29 | NORMAL | 2023-06-22T19:44:03.776738+00:00 | 2023-06-22T19:44:03.776759+00:00 | 18 | false | \n\n# Code\n```\nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n int ans=-1, min=INT_MAX;\n for(int i=0; i<points.size(); i++)\n {\n int a = points[i][0];\n int b = points[i][1];\n if(a==x || b==y)\n {\n... | 1 | 0 | ['C++'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Simple JAVA Solution for beginners. 2ms. Beats 67.96%. | simple-java-solution-for-beginners-2ms-b-xm11 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | sohaebAhmed | NORMAL | 2023-05-10T02:40:42.545968+00:00 | 2023-05-10T02:40:42.546015+00:00 | 82 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Array', 'Java'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Find Nearest Point That Has the Same X or Y Coordinate Solution in C++ | find-nearest-point-that-has-the-same-x-o-mnyz | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | The_Kunal_Singh | NORMAL | 2023-03-27T14:33:14.862592+00:00 | 2023-03-27T14:33:14.862624+00:00 | 74 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$... | 1 | 0 | ['C++'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Easy Java solution | easy-java-solution-by-kunal_kamble-9esf | \n# Code\n\nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n int index=-1;\n int min_distance=Integer.MAX_VALUE | kunal_kamble | NORMAL | 2023-03-19T09:52:28.471096+00:00 | 2023-03-19T09:52:28.471129+00:00 | 48 | false | \n# Code\n```\nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n int index=-1;\n int min_distance=Integer.MAX_VALUE;\n for (int i = 0; i < points.length; i++) {\n if(points[i][0]==x || points[i][1]==y){\n int distance=Math.abs(poin... | 1 | 0 | ['Java'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Solved with using boolean array | solved-with-using-boolean-array-by-vikin-0hun | 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 | viking09_ | NORMAL | 2023-03-06T10:59:25.458957+00:00 | 2023-03-06T10:59:25.458994+00:00 | 100 | false | # 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 whi... | 1 | 0 | ['Array', 'Java'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | [Ruby] O(n) solution | ruby-on-solution-by-artemtrepalin-rij0 | Code\n\n# @param {Integer} x\n# @param {Integer} y\n# @param {Integer[][]} points\n# @return {Integer}\ndef nearest_valid_point(x, y, points)\n res = -1\n min | ArtemTrepalin_ | NORMAL | 2023-02-25T11:12:53.974107+00:00 | 2023-02-25T20:11:17.695285+00:00 | 78 | false | # Code\n```\n# @param {Integer} x\n# @param {Integer} y\n# @param {Integer[][]} points\n# @return {Integer}\ndef nearest_valid_point(x, y, points)\n res = -1\n min_md = 9999999\n\n points.each_with_index do |point, index|\n next unless x == point[0] || y == point[1]\n next unless min_md > (x - point[0]).abs + ... | 1 | 0 | ['Ruby'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Java&Javascript Solution (JW) | javajavascript-solution-jw-by-specter01w-m0bl | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | specter01wj | NORMAL | 2023-01-24T17:19:06.042290+00:00 | 2023-01-24T17:19:06.042333+00:00 | 245 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Java', 'JavaScript'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Beats 97.73% | beats-9773-by-engeman08-v6m6 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | engeman08 | NORMAL | 2022-12-20T17:32:47.201079+00:00 | 2022-12-20T17:32:47.201109+00:00 | 42 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['TypeScript'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | JAVA SOLUTION 2ms runtime 🎃 | java-solution-2ms-runtime-by-harsh_singh-1q6c | Java Solution for \'Find Nearest Point That has the same X or Y Coordinate.\nRuntime - 2ms\nBeats - 95%\n\nclass Solution {\n public int nearestValidPoint(in | Harsh_Singh23_ | NORMAL | 2022-11-09T05:06:32.261214+00:00 | 2022-11-09T05:07:17.717477+00:00 | 13 | false | Java Solution for \'Find Nearest Point That has the same X or Y Coordinate.\nRuntime - 2ms\nBeats - 95%\n```\nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n int result = -1, minSum = Integer.MAX_VALUE;\n for (int i = 0; i < points.length; i++) {\n if (point... | 1 | 0 | ['Java'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | 📍 [ JAVA ] ✔ Faster than 100% ✔ Simple explanation 📢 | java-faster-than-100-simple-explanation-nvfit | Complexity:\nTime complexity: O(n)\nSpace complexity: O(1)\n\n\nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n \n | TristanCopley | NORMAL | 2022-11-07T03:56:47.708367+00:00 | 2022-11-07T19:27:51.382686+00:00 | 16 | false | **Complexity:**\n*Time complexity: O(n)\nSpace complexity: O(1)*\n\n```\nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n \n int index = -1;\n int closest = Integer.MAX_VALUE;\n int[] point;\n \n for (int i = 0; i < points.length; i++) {\n ... | 1 | 0 | ['Java'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | java | java-by-amitjha00-h797 | class Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n int a =0 ,b =0;\n var maxdis = Integer.MAX_VALUE;\n in | amitjha00 | NORMAL | 2022-10-10T08:09:30.075290+00:00 | 2022-10-10T08:09:30.075336+00:00 | 25 | false | class Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n int a =0 ,b =0;\n var maxdis = Integer.MAX_VALUE;\n int ans = -1;\n int sum =0;\n for(int i=0; i< points.length; i++){\n a = points[i][0];\n b = points[i][1];\n if(x==... | 1 | 0 | ['Java'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | JS | js-by-deleted_user-ik2k | \nconst nearestValidPoint = (x, y, points) => {\n const result = { distance: Infinity, index: -1 }\n for (let i = 0; i < points.length; i++) {\n if | deleted_user | NORMAL | 2022-10-09T07:12:22.962434+00:00 | 2022-10-09T07:12:22.962477+00:00 | 459 | false | ```\nconst nearestValidPoint = (x, y, points) => {\n const result = { distance: Infinity, index: -1 }\n for (let i = 0; i < points.length; i++) {\n if (points[i][0] === x || points[i][1] === y) {\n const calc = Math.abs(x - points[i][0]) + Math.abs(y - points[i][1])\n if (calc < resul... | 1 | 0 | [] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Easy Solution in Java for Beginners | easy-solution-in-java-for-beginners-by-h-dio1 | Intuition\n Describe your first thoughts on how to solve this problem. \nBruteforce\n\n# Approach\n Describe your approach to solving the problem. \nWe want A p | hashcoderz | NORMAL | 2022-10-07T06:11:56.527958+00:00 | 2022-10-07T06:11:56.527999+00:00 | 303 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nBruteforce\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe want A point that shares the same x-coordinate or the same y-coordinate as your location, dx * dy == 0 indicate either dx equals zero or dy equals zero,... | 1 | 0 | ['Array', 'Java'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Easy JavaScript with Comments | easy-javascript-with-comments-by-pratikv-c4tq | \nvar nearestValidPoint = function(x, y, points) {\n var distance=Infinity; //To keep track of smallest distance found\n var index=-1; //To keep track | pratikvpatil2002 | NORMAL | 2022-09-30T12:26:57.984364+00:00 | 2022-09-30T12:26:57.984405+00:00 | 17 | false | ```\nvar nearestValidPoint = function(x, y, points) {\n var distance=Infinity; //To keep track of smallest distance found\n var index=-1; //To keep track of index\n for(let i=0;i<points.length;i++){\n //If points are valid\n if(points[i][0]==x || points[i][1]==y){ \n //Calutating th... | 1 | 0 | [] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | 👩💻 Javascript: Arrow function with reduce O(N) | javascript-arrow-function-with-reduce-on-f4nl | \nconst nearestValidPoint = (x, y, points, min = Infinity) => \n points.reduce((res, [a,b], idx) => {\n if(a===x || b===y){\n const dist = | prajaktashirke20 | NORMAL | 2022-09-18T04:40:19.990987+00:00 | 2022-09-18T04:40:19.991019+00:00 | 304 | false | ```\nconst nearestValidPoint = (x, y, points, min = Infinity) => \n points.reduce((res, [a,b], idx) => {\n if(a===x || b===y){\n const dist = Math.abs(x-a) + Math.abs(y-b)\n if(dist<min){\n res = idx;\n min = dist;\n }\n }\n return r... | 1 | 0 | ['JavaScript'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | With Explanation Comments: Time: 342 ms (23.70%), Space: 59.4 MB (73.79%) | with-explanation-comments-time-342-ms-23-kydn | Like it? ->Upvote please! \u30C4\n\n\'\'\'\nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector>& points) {\n \n //initializ | deleted_user | NORMAL | 2022-09-17T19:28:14.047955+00:00 | 2022-09-17T19:28:14.048000+00:00 | 323 | false | **Like it? ->Upvote please!** \u30C4\n\n\'\'\'\nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& points) {\n \n //initialize a position & minimum possible absolute value & calculated distance variables\n int minValue=INT_MAX, dis=0, index=-1;\n \n ... | 1 | 0 | ['Array', 'C', 'C++'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | C++||Easy to Understand | ceasy-to-understand-by-return_7-ft7l | ```\nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector>& p) \n {\n int ans=INT_MAX,res=-1;\n for(int i=0;iabs(x-p[i][0] | return_7 | NORMAL | 2022-09-15T19:31:58.453298+00:00 | 2022-09-15T19:31:58.453338+00:00 | 131 | false | ```\nclass Solution {\npublic:\n int nearestValidPoint(int x, int y, vector<vector<int>>& p) \n {\n int ans=INT_MAX,res=-1;\n for(int i=0;i<p.size();i++)\n {\n if(x==p[i][0]||y==p[i][1])\n {\n if(ans>abs(x-p[i][0])+abs(y-p[i][1]))\n {\n ... | 1 | 0 | ['C'] | 0 |
find-nearest-point-that-has-the-same-x-or-y-coordinate | Java Solution 1ms 100% faster | java-solution-1ms-100-faster-by-mahmouds-5dxx | \nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n int [] solution = {0,Integer.MAX_VALUE};\n int index = 0;\ | MahmoudSafan | NORMAL | 2022-09-12T07:57:11.911867+00:00 | 2022-09-12T07:57:46.447804+00:00 | 92 | false | ```\nclass Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n int [] solution = {0,Integer.MAX_VALUE};\n int index = 0;\n for(int[] point:points){\n if(x == point[0] || y == point[1]){\n int sum = Math.abs(x - point[0]) + Math.abs(y - point[1])... | 1 | 0 | ['Array'] | 0 |
maximum-coins-from-k-consecutive-bags | [Java/C++/Python] Sliding Window | javacpython-sliding-window-by-lee215-3418 | IntuitionThe interval to pick will either/or
Start at A[i][0]
End at A[i][1]
ExplanationOne sliding window to check the interval starting at A[i][0].
One slidin | lee215 | NORMAL | 2025-01-05T04:21:19.900674+00:00 | 2025-01-05T07:02:43.800112+00:00 | 7,613 | false | # **Intuition**
The interval to pick will either/or
- Start at A[i][0]
- End at A[i][1]
# **Explanation**
One sliding window to check the interval starting at `A[i][0]`.
One sliding window to check the interval ending at `A[i][0]`.
`cur` is the `coins` from `k` consecutive bags.
`part` need to calculate if the edge i... | 91 | 2 | ['C++', 'Java', 'Python3'] | 13 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.