Versioned Snapshot Set
Problem statement
Implement a mutable set that can capture immutable snapshots and later return the entire set state stored at a selected snapshot.
Process these operations in input order:
["ADD", value]inserts an integer. Adding an existing value is a no-op.["REMOVE", value]removes an integer. Removing a missing value is a no-op.["SNAPSHOT"]captures the current set, assigns the next consecutive zero-based snapshot identifier, and emits[identifier].["GET_SNAPSHOT", identifier]emits every value captured by that snapshot as decimal strings in ascending numeric order.
ADD and REMOVE emit no result row. Later mutations never change an existing snapshot. Return the emitted rows in operation order.
Function
runSnapshotSet(operations: String[][]) → String[][]Examples
Example 1
operations = [["ADD","1"],["ADD","3"],["SNAPSHOT"],["REMOVE","3"],["ADD","2"],["GET_SNAPSHOT","0"],["SNAPSHOT"],["GET_SNAPSHOT","1"]]return = [["0"],["1","3"],["1"],["1","2"]]Snapshot 0 preserves {1, 3} despite later mutations. Snapshot 1 captures {1, 2}.
Constraints
1 <= operations.length <= 200000- Values are integers in
[-10^9, 10^9]. - At most 20000 snapshots are created.
- The sum of current-set sizes across SNAPSHOT operations is at most 200000.
- The total number of values returned across GET_SNAPSHOT operations is at most 200000.
- Every GET_SNAPSHOT identifier refers to an existing snapshot.