Versioned Array Snapshots

Implement a versioned array supporting snapshots. You are given two arrays operations and args describing a sequence of calls. Return an array outputs where outputs[i] is the return value of operations[i].

Operations:

  • SnapshotArray — constructor, args[i] = [length], initialize array of given length filled with 0, returns null.
  • set — args[i] = [index, val], sets arr[index] = val, returns null.
  • snap — args[i] = [], takes a snapshot, returns current snap_id (starting at 0 and incrementing by one per snap).
  • get — args[i] = [index, snap_id], returns value at index at the time snapshot snap_id was taken.

snap() increments the snapshot id after capturing the current state. Every get references a snap_id that already exists.

Your function solve(operations, args) must dispatch these calls and collect outputs, using null for void returns.

Examples
Input: [["SnapshotArray","set","snap","set","get"],[[3],[0,5],[],[0,6],[0,0]]]
Output: [null,null,0,null,5]
Hints
Related Problems

Versioned Array Snapshots

Implement a versioned array supporting snapshots. You are given two arrays `operations` and `args` describing a sequence of calls. Return an array `outputs` where `outputs[i]` is the return value of `operations[i]`.