Answer: Adobe OA Question 2024 August | Heaps | on-campus

Answer · Posted Jun 2026

Solution: K Closest Points to Origin — Max Heap of Size K Approach We use a Max Heap of size K to efficiently track the K closest points. We compare squared distances to avoid computing square roots (which preserves order). For each point, compute its squared distance: x*x + y*y. Add the point to a max heap keyed by distance. If the heap size exceeds k, remove the farthest point (top of the max heap). After processing all points, the ...

The full answer & interview discussion are available to premium members.

Log in Create a free account