Without reading the provided solution (which I’d like to delay doing as long as possible), it’s unclear to me what “size” means in the problem description.
The example given to illustrate the use of size is: an array <a,b,a,c,_> and size 4, where <d,d,d,d,c> is the result after performing the replace and remove operations.
In the example, what is the number of entries that the operations have been applied to?
Is it 3, because we replaced and removed 2 a’s and 1 b? Or is it 5, because, in the course of performing the operations, we modified the entries in 5 positions of the array?
Also, why is the last entry in the array denoted “_”? Is it to indicate that the actual value of the entry at that position is irrelevant to the explanation being given? Or does it indicate that, at some positions in the array, there may be no entry i.e. a null value?