For people having TLE with O(n)


At least in Java the remove() method takes O(n-1) worst time complexity. I assume in other languages it is a similar case, e.g in python I think pop is O(1) only if it is top of the list. Etc.
Therefore, they want you to modify the existing array in such a way that the values which should be present in the array should be added in the starting of the array. and the size of array which you return is actually the length of this array to which it(the judge) will check. I don’t think this is explained properly and doing it in O(1) space this seems to be the wanted method.