Snapshot Array
Medium · Binary Search · about 25 minutes
Asked at Google, Amazon, Apple, MongoDB, Uber.
Implement an array that supports snapshots.
SnapshotArray(length)creates an array oflengthzeros.set(index, val)sets the element atindex.snap()takes a snapshot and returns its id: the first snapshot is 0, the next 1, and so on.get(index, snap_id)returns the value atindexwhen snapshotsnap_idwas taken.