Question DSA-HEAP-0062
HardWhat is the output of this code?
import heapq
def k_closest(pts, k):
return heapq.nsmallest(k, pts, key=lambda p: p[0] ** 2 + p[1] ** 2)
print(k_closest([(1, 3), (-2, 2), (5, 8), (0, 1)], 2))
- A.
[(-2, 2), (0, 1)]
- B.
[(0, 1), (-2, 2)]
- C.
Sign up free to see the answer and a step-by-step explanation.