Two structures holding hands: designing data structures

A hash map finding a key in one step, the tool that every structure in this lesson leans on.
An interviewer says: “Build a set where you can insert, delete and also pick a random member, each in constant time.” You know a list can pick a random member. You know a hash map can delete in one step. Neither can do all three. A list is slow to delete from the middle. A hash map has no positions, so it cannot pick at random. The question is not asking for a new idea. It is asking you to combine two ideas you already have so that each covers the weakness of the other.
By the end you will be able to solve three such problems (a random set, a snapshot array and an LFU cache) and to run the same five-step method on any “design a data structure” question.
The history (optional)
A cache that throws out the least recently used entry (LRU) can be built with O(1) work per operation. A cache that throws out the least frequently used entry (LFU) was long thought to need a heap, which costs O(log n) per operation. A paper dated 16 August 2010, “An O(1) algorithm for implementing the LFU cache eviction scheme” by Ketan Shah, Anirban Mitra and Dhruv Matani, showed that a hash table and linked lists are enough. The idea is in the third section below, and nothing later in the lesson depends on this note.
Before you start. Design an LRU cache (a map and a list that keep each other honest) showed a hash map and a linked list that always describe the same entries. That promise is called an invariant, and every method must leave it true. Hashing gave you the hash map: a key goes in and its value comes out in one step. Clinic #11: Binary Search gave you binary search: find a value in a sorted list by halving the range. Design a parking lot (the first whole round) gave you the order of a design round. You also need to read a little Python.