LeetCode Problem 973: K Closest Points to Origin with Heap Approach

🗓 7 April 2026 🚀 LeetCode Problem #973 — K Closest Points to Origin Solved this problem using a Heap (Priority Queue) approach in Python. 💡 Approach: - Calculated the distance of each point from origin using: 👉 x² + y² (no need for square root) - Used a max heap (by pushing negative distance) - Maintained heap size = k - If size exceeds k → removed the farthest point ⚡ Time Complexity: O(n log k) ⚡ Space Complexity: O(k) 🔥 This is a great example of optimizing from brute force (sorting O(n log n)) to a more efficient heap-based solution. Consistency update: solving problems daily and improving problem-solving skills step by step. #leetcode #dsa #python #coding #100DaysOfCode #heaps #learning

  • graphical user interface, text

To view or add a comment, sign in

Explore content categories