From d733ca43e978f8d983288a70a41442d9069d6360 Mon Sep 17 00:00:00 2001 From: Deven <63876261+devenperez@users.noreply.github.com> Date: Thu, 2 Oct 2025 12:50:43 -0400 Subject: [PATCH] Create README - LeetHub --- 1146-snapshot-array/README.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 1146-snapshot-array/README.md diff --git a/1146-snapshot-array/README.md b/1146-snapshot-array/README.md new file mode 100644 index 0000000..0d0c295 --- /dev/null +++ b/1146-snapshot-array/README.md @@ -0,0 +1,33 @@ +
Implement a SnapshotArray that supports the following interface:
+ +SnapshotArray(int length) initializes an array-like data structure with the given length. Initially, each element equals 0.void set(index, val) sets the element at the given index to be equal to val.int snap() takes a snapshot of the array and returns the snap_id: the total number of times we called snap() minus 1.int get(index, snap_id) returns the value at the given index, at the time we took the snapshot with the given snap_id+
Example 1:
+ ++Input: ["SnapshotArray","set","snap","set","get"] +[[3],[0,5],[],[0,6],[0,0]] +Output: [null,null,0,null,5] +Explanation: +SnapshotArray snapshotArr = new SnapshotArray(3); // set the length to be 3 +snapshotArr.set(0,5); // Set array[0] = 5 +snapshotArr.snap(); // Take a snapshot, return snap_id = 0 +snapshotArr.set(0,6); +snapshotArr.get(0,0); // Get the value of array[0] with snap_id = 0, return 5+ +
+
Constraints:
+ +1 <= length <= 5 * 1040 <= index < length0 <= val <= 1090 <= snap_id < (the total number of times we call snap())5 * 104 calls will be made to set, snap, and get.