Remove Duplicate from Array in Place in Python
Remove Duplicate from Array in Place
In this article, I'll share some methods to remove duplicates from an array
one of them is how to do it in place that means with O(1) space complexity.
Now, we can do this by maintaining an extra pointer
"x" which holds the last index of a
nonduplicate value in an array. Let's make it simple, of course, the length of a resultant array will be less than the original array that contains duplicate values. So by shifting all nonduplicate values to the front of an array might solve our problem. Look at the following figure:
But to perform the in-place operation you need to sort the array first!
which take O(nlogn).
Here are some native methods:
Thank you so much for reading this article, if you like this question please share this with your friends who love programming. And if you have questions or feedback please drop a comment.
To solve more problems please check this article "Top 10 Array Interview Questions".
All the Best!
Comments
Post a Comment