Remove Duplicates from Sorted Array in Python

Day 8 of 365 days of code: Qn 1) Remove the duplicates from the array. Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Consider the number of unique elements in nums to be k. After removing duplicates, return the number of unique elements k. The first k elements of nums should contain the unique numbers in sorted order. The remaining elements beyond index k - 1 can be ignored. use two pointer technique. let L=1 starting from position r=1, we overwrite the number at L if nums[r-1]!=nums[r]. this process is like copy pasting the unique elements on the left side of the array, in a sorted order. #365daysOfCode #NeetCode #leetcode #DSA #python #LeetCode #ProblemSolving #Algorithms #365dayschallenge

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories