Solution: Snapshot Array
Explore the implementation of a Snapshot Array, focusing on managing array values across snapshots using efficient custom data structures. Understand naive and optimized approaches, evaluate their time and space complexities, and learn to create a solution that supports setting values, taking snapshots, and fetching values from specific snapshots.
Statement
In this challenge, you have to implement a Snapshot Array with the following properties:
-
NewSnapshotArray (length): Initializes the data structure to hold the specified number of indexes.
-
Set Value (idx, val): This property sets the value at a given index idx to value val.
-
Snapshot(): This method takes no parameters and returns the Snap ID. Snap ID is the number of times that the snapshot function was called, less , as we start the count at . The first time this function is called, it saves a snapshot and returns . The time it is called, after saving the snapshot, it returns .
-
Get Value (idx, Snap ID) method returns the value at the index in the snapshot with the given Snap ID. ...