Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

points =
k =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Pick the k points with smallest squared distance to the origin.

Approach

Use a heap helper to select k smallest by key x^2 + y^2 (no need for square root).

Why it works

Squared distance preserves ordering and heap selection returns the k closest.

Code
Loading...
Complexity
Time: O(n log k)
Space: O(k)
Solution
Updated: 2026-02-23

Idea

Pick the k points with smallest squared distance to the origin.

Approach

Use a heap helper to select k smallest by key x^2 + y^2 (no need for square root).

Why it works

Squared distance preserves ordering and heap selection returns the k closest.

Code
Loading...
Complexity
Time: O(n log k)
Space: O(k)