Remove Duplicates from Sorted Array on LeetCode

🚀 End of the Week LeetCode Practice Wrapping up this week’s coding practice with another problem from the array collection on LeetCode: Remove Duplicates from Sorted Array. It’s the end of the week, and I’m glad to say I’ve already knocked down 2 problems while continuing to sharpen my problem-solving skills. 🔎 Problem Overview Given a sorted array, the task is to remove duplicates in-place so that each element appears only once. The function should return the number of unique elements (k), and the first k positions of the array should contain those unique values. The challenge is doing this without using extra space, meaning we must modify the original array efficiently. 🧠 Approach Because the array is already sorted, duplicate values appear next to each other. This makes the two-pointer technique a clean and efficient solution. • Pointer i tracks the position of the last unique element • Pointer j scans through the array • When a new unique value appears, i moves forward and we update the array This keeps the solution efficient with: • Time Complexity: O(n) • Space Complexity: O(1) ⚙️ Performance • Runtime: 4 ms (Beats 42.04%) • Memory Usage: 13.92 MB (Beats 38.66%) 💡 I’ve featured the full implementation in my LeetCode library on my LinkedIn profile, where I’m documenting my problem-solving journey. Feel free to check it out there. 📊 Week Summary ✔ Solved 2 LeetCode problems ✔ Practiced array manipulation and pointer techniques ✔ Continued building consistency in coding practice Now it's time to reset, recharge, and start getting ready for next week’s challenge. #LeetCode #Algorithms #Python #DataScienceJourney #MachineLearning #CodingPractice #ProblemSolving

To view or add a comment, sign in

Explore content categories