New course! Every coder should learn Generative AI!
Try a free lesson+ 9
I wasn't really sure how to explain this so instead am giving you the code.
https://code.sololearn.com/ckExmpj8vMA8
Beyond this method, you could shift the array contents down to remove elements.
Another way to do it would be with a linked list so you could delete the elements from the list.