Dsa
Heap
Easy
K Closest Points to Origin
Given a list of points in 2D space and an integer k, find the k closest points to the origin (0, 0). Your solution should return the points as a list.
Input:
- The first line contains an integer k.
- The following lines contain space-separated coordinates of points (x, y).
Output:
- A list of k closest points as a string in the format: [(x1, y1), (x2, y2), ...]
Example:
Input:
2
1 2
2 2
4 4
1 -1
-1 -1
Output:
[(1, -1), (1, 2)]
Key concepts
heapdistancegeometry
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now