Notepad/enter/Coding Tips (Classical)/Project Vault/Past Projects/Amazon Programming Tips/Coding Assessment/ipynb practice problems/Notebook code/K Closest Points to Origin(...

1 line
1.6 KiB
Plaintext

{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"K Closest Points to Origin(973).ipynb","provenance":[],"authorship_tag":"ABX9TyPPXwejMq9b9je8LJjGDe8j"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["# 973. K Closest Points to Origin\n","Medium\n","5755\n","212\n","Add to List\n","Share\n","Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0).\n","The distance between two points on the X-Y plane is the Euclidean distance (i.e., √(x1 - x2)2 + (y1 - y2)2).\n","You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in).\n"," \n","Example 1:\n","\n","Input: points = [[1,3],[-2,2]], k = 1\n","Output: [[-2,2]]\n","Explanation:\n","The distance between (1, 3) and the origin is sqrt(10).\n","The distance between (-2, 2) and the origin is sqrt(8).\n","Since sqrt(8) < sqrt(10), (-2, 2) is closer to the origin.\n","We only want the closest k = 1 points from the origin, so the answer is just [[-2,2]].\n","\n","Example 2:\n","Input: points = [[3,3],[5,-1],[-2,4]], k = 2\n","Output: [[3,3],[-2,4]]\n","Explanation: The answer [[-2,4],[3,3]] would also be accepted.\n","\n"," \n","Constraints:\n","1 <= k <= points.length <= 104\n","-104 < xi, yi < 104\n"],"metadata":{"id":"x-sKjh1g1iNk"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"x8F1f23v1g8y"},"outputs":[],"source":["# https://developers.google.com/maps/documentation/javascript/reference/marker"]}]}