Solution: Snapshot Array
Explore how to implement the Snapshot Array data structure in C# by learning both naive and optimized approaches using nested dictionaries. Understand methods to set values, take snapshots, and retrieve values efficiently while balancing time and space complexity. This lesson deepens your knowledge of custom data structures for managing data snapshots and is crucial for coding interview preparation.
Statement
In this challenge, you have to implement a Snapshot Array with the following properties:
-
Constructor (length): This is the constructor and it 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 ...