I have a sorted Array:
let mySortedArray = [1,1,5,6,8,8,9,25,25]
I want to remove any duplicates from this array in O(1) time and space complexity. First of all, is this even possible?
My solution is the following: I convert the array to a set and any duplicates are just removed.
let mySet = new Set(myArray);
What would the time and space complexity of that be?
And if I were to convert the set back to an Array:
let myNewArr = Array.from(mySet);
What would the time and space complexity of the whole method then be?
Would this be the most optimal way of removing any duplicates of an array or would there be a better one?