Description
Implement a SnapshotArray that supports set(index, val), snap(), and get(index, snap_id). snap() takes a snapshot and returns the snap_id. Return the result as an integer.
Examples
Input:
set(0, 5), snap(), set(0, 6), get(0, 0)Output:
5Explanation:
Snapshot 0 had value 5 at index 0, so the result is 5.
Input:
set(1, 10), set(3, 20), snap(), set(1, 15), snap(), get(1, 0), get(3, 1), get(1, 1)Output:
10, 20, 15Explanation:
Getting the queried values across snapshots returns 10, 20, and 15, so the result is "10, 20, 15".
Input:
snap(), get(2, 0), set(2, 100), get(2, 0), snap(), get(2, 1)Output:
0, 0, 100Explanation:
The queried values across snapshots are 0, 0, and 100, so the result is "0, 0, 100".
Constraints
- •
1 ≤ length ≤ 5 × 10⁴ - •
0 ≤ index < length - •
0 ≤ val ≤ 10⁹