...

/

Solution: Snapshot Array

Solution: Snapshot Array

Let's solve the Snapshot Array problem using the Custom Data Structures pattern.

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 11, as we start the count at 00. The first time this function is called, it saves a snapshot and returns 00. The nthn^{th} time it is called, after saving the snapshot, it returns n1n-1.

  • Get Value (idx, Snap ID) method returns the value at the index in the snapshot with the given Snap ID.

Suppose that we have three nodes whose values we wish to track in the snapshot array. Initially, the value of all the nodes will be 0 ...

Access this course and 1400+ top-rated courses and projects.