🗓 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
LeetCode Problem 973: K Closest Points to Origin with Heap Approach
More Relevant Posts
-
🚀 Day 89 of #100DaysOfCode Solved LeetCode Problem 231 — Power of Two ✅ Cracked this one with a clean and efficient bit manipulation approach. The goal was to check whether a number is a power of two without using loops or recursion. 💡 Key Insight: A power of two has exactly one set bit in its binary form. So, using the trick: 👉 "n > 0 and (n & (n - 1)) == 0" This removes the lowest set bit — if the result is 0, it's a power of two. ⚡ Performance: • Runtime: 0 ms (Beats 100%) • Memory: 19.27 MB 🔍 What I learned: • Bit manipulation is insanely powerful • Writing optimal solutions matters • Small tricks can save big time Consistency > Motivation. On to Day 90 🔥 #LeetCode #DSA #CodingJourney #100DaysChallenge #BitManipulation #Python
To view or add a comment, sign in
-
-
Day 1 of my LeetCode journey 🚀 🧩 Problem: Minimum Distance to the Target Element (1848) 💡 Approach: Looped through the array and tracked the minimum absolute difference whenever the target appeared. 📚 What I learned today: • How to iterate through a list efficiently • Using abs() to compute absolute difference • Tracking minimum values during iteration • Initializing variables correctly using infinity • Better understanding of loops and conditional checks in Python 🛠 Language Concepts Used: • for-loop • if condition • abs() function • min() logic / running minimum ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) 🔗 GitHub: https://lnkd.in/gZ23dWkV #LeetCode #Python #DSA #100DaysOfCode #LearningInPublic
To view or add a comment, sign in
-
-
🚀 LeetCode Progress Update – Problem Solved! ✅ Problem: Remove Trailing Zeros From a String 💡 Approach: Used reverse traversal to find the first non-zero digit and sliced the string accordingly. 🔍 Key Learning: Efficient string manipulation can avoid unnecessary conversions. Traversing from the end helps solve trailing-based problems quickly. 💻 Code Insight: Instead of removing zeros one by one, I identified the breakpoint and sliced the string — making it optimal and clean. ⏱️ Performance: Runtime: 3 ms ⚡ Beat: 66%+ users Memory: 19.23 MB 📈 Consistency is key — one problem closer to mastery! #LeetCode #CodingJourney #Python #ProblemSolving #DSA #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Week 2 — DSA + System Design This week I focused on making my basics stronger. 📚 DSA (C++ & Python): • Practiced Arrays again • Worked more on Time & Space Complexity • Learned Binary Search and solved different types of problems • Solved around 30–35 questions 🏗️ System Design (LLD): • Revised OOP concepts • Practiced writing cleaner and better structured code ❌ Challenges: Binary Search was confusing in different problems Applying time complexity in real questions was not easy 💡 Realization: Now I’m starting to understand when to use which approach 🎯 Week 3 Goal: Start Linked List and Recursion Staying consistent. Chandan Kumar #DSA #SystemDesign #BuildInPublic #LearningInPublic
To view or add a comment, sign in
-
🚀 Day 55 of my Problem Solving Journey Solved Remove Spaces today — a simple yet important string manipulation problem. 💡 Key Learning: Sometimes the easiest problems reinforce the strongest fundamentals. Efficient string handling and clean code matter just as much as complex algorithms. Explored multiple approaches — from built-in methods like "replace()" to manual iteration — and understood how each impacts readability and performance. Small steps like these build consistency and sharpen problem-solving skills over time. 💻 #geekstreak60 #npci #GeeksforGeeks #DSA #Python #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
📅 7 April 2026 Solved Median Finder (Two Heaps) problem today on LeetCode. Initially, I was getting wrong answers even though the logic looked correct. The mistake? Comparing directly with a max heap stored as negative values. 🔍 Key Learning: When using a max heap in Python (via negative values), always convert back before comparison. ❌ Wrong: num < self.left[0] ✅ Correct: num <= -self.left[0] 💡 Approach: - Use two heaps: • Max Heap (left) → stores smaller half • Min Heap (right) → stores larger half - Balance both heaps after every insertion - Median depends on heap sizes 📈 Time Complexity: - addNum → O(log n) - findMedian → O(1) Small bug, big learning 🚀 Consistency in DSA is what builds clarity. #leetcode #dsa #python #heaps #codingjourney #problemSolving
To view or add a comment, sign in
-
-
Day 111 Backtracking is starting to feel consistent now. #Day111 🧩 39. Combination Sum How today went: • Used backtracking with index i • Two choices: → stay at i (reuse the same element) → move to i + 1 (try next element) • Track the current total • If total == target → add result • If total > target → stop that path What I realized: This problem is about: → controlling index movement → managing the running total Same pattern, different control. Revision is making it clearer. #LeetCode #DSA #Python #Backtracking #Recursion #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
🚀 Day 85 of #100DaysOfLeetCode 🔍 Problem Solved: Ransom Note (LeetCode 383) Today’s problem was all about efficiently checking whether one string can be constructed from another — a classic hashing / frequency counting concept. ⚡ What I Learned: - Importance of frequency maps (hash tables) - Writing optimized solutions over naive approaches - How built-in methods can simplify logic but may impact performance 📊 Performance: ✅ Runtime: 0 ms (Beats 100%) ✅ Memory: Efficient usage 🔥 Takeaway: Small optimizations and choosing the right data structure can make a huge difference, even in easy problem #Day85 #LeetCode #CodingJourney #Python #DataStructures #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Just solved “Second Largest Digit in a String” on LeetCode — and here’s the simple approach I followed 👇 Instead of overcomplicating it, I focused on clean thinking + Python basics: 🔹 Converted the string into a set → removes duplicates instantly 🔹 Filtered only digits using isdigit() 🔹 Stored them as integers in a list 🔹 Sorted the list → easy access to largest & second largest 🔹 Edge case check: if less than 2 digits → return -1 💡 Key takeaway: Sometimes the most optimal solution isn’t about complex algorithms — it’s about using the right built-in tools smartly. 🚀 What I’m improving with each problem: • Writing cleaner logic • Thinking in steps instead of rushing • Handling edge cases early Consistency > Complexity. #LeetCode #DSA #Python #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 119 Same problem family, new constraint — but now it feels easier. #Day119 🧩 40. Combination Sum II How today went: • Very similar to Combination Sum • First step: sort the array • Move to i + 1 (each element used once) • Skip duplicates to avoid repeating combinations Key idea: 👉 No reuse of same element 👉 Handle duplicates carefully What I realized: Once you understand the base pattern, variants like this become much easier. Backtracking is starting to feel natural now. #LeetCode #DSA #Python #Backtracking #Recursion #LearningInPublic #Consistency
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development