O88
Snapshot Array
Problem Statement & Objective
Implement a SnapshotArray that supports pre-allocation, element setting, taking snapshots with unique snapshot IDs, and querying historical values.
Function Signature (Python)
snapshot_array(length: int, operations: list) -> listInput & Output Contract
Output Rule:Her işlem sonucunu içeren liste (None veya int).
System Constraints
1 <= uzunluk <= 5 * 10^4
1 <= islemler.length <= 5 * 10^4
0 <= index < uzunluk
0 <= val <= 10^9Example Execution Walkthrough
uzunluk = 3, islemler = [['set', 0, 5], ['snap'], ['set', 0, 6], ['get', 0, 0]]
set 0 5 -> [5, 0, 0]
snap -> snap_id 0
set 0 6 -> [6, 0, 0]
get(0, snap_id=0) -> snap_id 0 anında değer 5 idi -> 5
Cevap: [None, 0, None, 5]Example Test Scenarios (3)
Example 1: Temel Snapshot
Input:
[3,[["set",0,5],["snap"],["set",0,6],["get",0,0]]]Expected Output:
[null,0,null,5]Example 2: Çoklu Snap
Input:
[1,[["set",0,15],["snap"],["snap"],["get",0,1]]]Expected Output:
[null,0,1,15]Example 3: Varsayılan Sıfır Değeri
Input:
[2,[["snap"],["get",0,0]]]Expected Output:
[0,0]