Domanda di colloquio di Peloton Interactive

Implement a list-based data structure that performs inserts and deletes in constant time.

Risposta di colloquio

Anonimo

24 mag 2023

Use a list to store the items, use a dictionary to store the indices of each item in the list. Perform deletes by swapping the item at the end for the item to be deleted, and then truncating the list by 1 item.