As reported: Rubrik software engineer loop (2025), round 1 — system coding: LeetCode 1146.
This is LeetCode 1146 — Snapshot Array.
Implement SnapshotArray:
SnapshotArray(length)— an array oflengthelements, all0.set(index, val)— sets the element atindextoval.snap()— takes a snapshot and returns its id: the first snapshot has id0, the next1, and so on.get(index, snap_id)— the value atindexat the time of snapshotsnap_id.
Example
["SnapshotArray","set","snap","set","get"]
[[3],[0,5],[],[0,6],[0,0]]
-> [null,null,0,null,5]
Constraints: 1 ≤ length ≤ 5·10^4; 0 ≤ index < length; 0 ≤ val ≤ 10^9; 0 ≤ snap_id < number of snap() calls so far; at most 5·10^4 calls in total.
Code runner format: LeetCode's design format — line 1 the method names, line 2 their arguments. Implement the SnapshotArray class; the harness prints the list of results.