Nested Map | Java | Solution | Easy to Understand
\nclass SnapshotArray {\n    Map<Integer,Map<Integer,Integer>> map =  new HashMap<>();\n    int cnt =0;\n    public SnapshotArray(int length) {\n        \n    }
```\nclass SnapshotArray {\n    Map<Integer,Map<Integer,Integer>> map =  new HashMap<>();\n    int cnt =0;\n    public SnapshotArray(int length) {\n        \n    }\n    \n    public void set(int index, int val) {\n        map.putIfAbsent(cnt,new HashMap<>());\n        map.get(cnt).put(index,val);\n    }\n    \n    public int snap() {\n        cnt++;\n        return cnt-1;\n    }\n    \n    public int get(int index, int snap_id) {\n        for(int i=snap_id;i>=0;i--){\n             if(map.containsKey(i) && map.get(i).containsKey(index))\n                 return map.get(i).get(index);\n        }\n        return 0;\n    }\n}\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * SnapshotArray obj = new SnapshotArray(length);\n * obj.set(index,val);\n * int param_2 = obj.snap();\n * int param_3 = obj.get(index,snap_id);\n */\n```
[]