Swap with last for constant-time deletion [mp]
Micro pattern¶
Description¶
Replace a removed array element with the last element, update its index, and pop.
Problems¶
- 380. Insert Delete GetRandom O(1) (Top Medium)
Replace a removed array element with the last element, update its index, and pop.