Only queues are designed to add/delete one element at a time. Dynamic arrays must be sized as a whole array.
It’s not clear what you are trying to accomplish with your non-functioning code. It’s not a good idea to iterate over an array as you are changing its size.
I do not understand your question. What do you mean by “distinct” in terms of elements of an array. Can you give me an input array example and output array you are expecting.
You can always copy a dynamic array to a queue, then delete the elements you want, then, copy it back to the dynamic array.