I have the following task (as part of a larger task):
I need to take element k from the array as a data structure and delete it (k is any possible index). An array has O (n) for deleting elements, and List has O (n) for a search element. I would like to do both operations O (1) times.
What data structure should I use to meet this requirement?
Clarification:
Removing an element by index (5) will move the element from index (6) to index (5).
This task is the problem of topcoder srm 300 div2 500 points. It does not require such a complex data structure (simple java methods will do the job, since the maximum data is really small), but I'm curious how to deal with a much bigger problem using a c-shaped representation of the data.
So maybe I am very attached to this problem? But I will analyze it and edit the question later, after work (if you are really interested, you can see the task on the upper encoder).
source share