I have one newArray and one oldArray as follows. If newArray has anyitem which exists in the oldArray, then I want to delete it from oldArray. I could able to run two nested for loop and detect duplicates to remove, but it will be O(n2). I wonder if there is a better way to handle?
I cannot use Set, because order needs to be kept.
newArray = [2,4,5]
oldArray = [1,2,3,5]
newArray = [2,4,5,1,3] // append newArray and oldArray.