Remove Array Duplicates with In-Place Modification

🧩 Problem: Remove Duplicates from Array (LeetCode #26) 💡 Concept Learned: This problem taught me the importance of In-place Modification. Instead of creating a new list, I modified the original array to save memory, ensuring the first k elements are the unique ones. 🔍 Key Insight: The Memory (Set): I used a Python Set to instantly check if a number was already seen.The Writer (Pointer k): I maintained a pointer k to track where the next unique element should be placed.The Strategy: When a "new" number is found, I overwrite nums[k] and increment k. This keeps all unique values at the front of the line. 🎯 Key Takeaway: Indentation is Logic: In Python, the placement of a return statement is the difference between a finished loop and an early exit. Efficiency: Using a Set makes lookups , making the overall solution time complexity. Growth: Every bug (like a NameError or a misplaced return) is just a lesson in disguise. 📈 Slowly building confidence by solving one problem at a time and learning from mistakes. #DSA #LeetCode #100DaysOfCode #TwoPointers #ProblemSolving #Python #CodingJourney #LearningInPublic #CodeNewbie

  • graphical user interface, text, application

To view or add a comment, sign in

Explore content categories