Intuitive Java Solution With Explanation
Idea\nMaintain map of changes where key is index. Everytime snap is called, add the copy to snaps. This will be faster if there are many unchanged values betwee
**Idea**\nMaintain map of `changes` where key is index. Everytime snap is called, add the copy to `snaps`. This will be faster if there are many unchanged values between snaps as we only record changes between snaps (like `git`).\n\n```\nclass SnapshotArray {\n    int snapId = 0;\n    Map<Integer, Integer> changes = new HashMap<>();\n    List<Map<Integer, Integer>> snaps = new ArrayList<>();\n    public SnapshotArray(int length) {\n        \n    }\n    \n    public void set(int index, int val) {\n        changes.put(index, val);\n    }\n    \n    public int snap() {\n        Map<Integer, Integer> copy = new HashMap<>();\n        copy.putAll(changes);\n        snaps.add(copy);\n        ++snapId;\n        return snapId-1;\n    }\n    \n    public int get(int index, int snap_id) {\n        Map<Integer, Integer> m = snaps.get(snap_id);\n        return m.getOrDefault(index, 0);\n    }\n}\n```
[]