K Closest Points to Origin Visualizer & Solution | Rulcode
Loading problem details...
150. K Closest Points to Origin
Medium
Topics
Companies
Hint
Understand Before Coding
Visualize This Problem
Open Visualizer
Draw Your Approach
Draw
Example 1:
Input:points = [[1,3],[-2,2]], k = 1
Output:[[-2,2]]
Explanation:The distance of [1,3] from origin is sqrt(10). The distance of [-2,2] from origin is sqrt(8). Since sqrt(8) < sqrt(10), [-2,2] is closer. Since k=1, we only return the closest one.
Example 2:
Input:points = [[3,3],[5,-1],[-2,4]], k = 2
Output:[[3,3],[-2,4]]
Explanation:The two closest points to the origin are [3,3] and [-2,4].