Simple Java Solution using HashMap | 36ms Faster than 90.38%
Please upvote, if you find it useful :)\n\n\nclass SnapshotArray {\n\n    public HashMap<Integer, Integer>[] snapshotMap;\n    public int snapID;\n    \n    pub
Please upvote, if you find it useful :)\n\n```\nclass SnapshotArray {\n\n    public HashMap<Integer, Integer>[] snapshotMap;\n    public int snapID;\n    \n    public SnapshotArray(int length) {\n        snapID = 0;\n        snapshotMap = new HashMap[length];\n        \n        for(int i=0; i<length; i++) {\n            snapshotMap[i] = new HashMap<>();\n        }\n    }\n    \n    public void set(int index, int val) {\n        snapshotMap[index].put(snapID, val);\n    }\n    \n    public int snap() {\n        snapID += 1;\n        return snapID - 1;\n    }\n    \n    public int get(int index, int snap_id) {\n        while(snap_id >= 0) {\n            if(snapshotMap[index].containsKey(snap_id)) {\n                return snapshotMap[index].get(snap_id);\n            }\n\n            snap_id -= 1;\n        }\n        \n        return 0;\n    }\n}\n\n```
['Java']