Easy · Hash Maps

Find K Closest to Center

Given a list of integer points and an integer k, return the k points closest to the origin (0, 0) by Euclidean distance, in any order.

Examples

Example 1

[(1,3),(-2,2),(5,8),(0,1)] k=2

Output: (0,1), (-2,2)

Example 2

[(3,3),(5,-1),(-2,4)] k=2

Output: (3,3), (-2,4)

Rebuild it in the studio

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Hash Maps problems