Python Dictionary
The idea is to capture the changes for a current version (snap_cnt) in a dictionary. Each snapshot is stored in another dictionary which holds the snap_cnt as a
The idea is to capture the changes for a current version (`snap_cnt`) in a dictionary. Each snapshot is stored in another dictionary which holds the `snap_cnt` as a key and the changes as a value.\n\nWhen retrieving a value (`get(...) method`), it will travel back to previous versions until a value for a requested index is found. If value is not found, return a default value `0`.\n\n```py\nfrom collections import defaultdict\nclass SnapshotArray:\n\n    def __init__(self, length: int):\n        self.snaps = defaultdict(defaultdict)\n        self.snap_cnt = 0\n\n    def set(self, index: int, val: int) -> None:\n        self.snaps[self.snap_cnt][index] = val\n\n    def snap(self) -> int:\n        self.snap_cnt += 1\n        return self.snap_cnt - 1\n\n    def get(self, index: int, snap_id: int) -> int:\n        cur = snap_id\n        while cur > 0 and index not in self.snaps[cur]:\n            cur -= 1\n        if index in self.snaps[cur]:\n            return self.snaps[cur][index]\n        return 0\n```\t\t
[]