Your question is O(1) List Pop. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Bloomberg Law may maintain in-memory work queues where processing order is unimportant. Implement a function that removes and returns the item at a specified index in O(1) time.
Because shifting elements would require linear time, preserve the complexity requirement by replacing the removed item with the final list element, then removing the final slot. This operation does not preserve the original order of the remaining items.
Implement pop_constant_time(items, index):
items is a non-empty Python list of values.index is a valid integer index from 0 through len(items) - 1.items in place.items[index].def pop_constant_time(items, index):