Java Single Map, Composite Index
\n Current snap id is already decided\n Doesn\'t store any 0s or empty records. Stores only the index and value.\n* In the get(index, snap_id) function, do look
\n* Current snap id is already decided\n* Doesn\'t store any 0s or empty records. Stores only the index and value.\n* In the get(index, snap_id) function, do lookup in the same HashMap\n\n\n```\nclass SnapshotArray {\n    HashMap<String, Integer> snaps = new HashMap<String, Integer>();\n    int currentSnapId = 0;\n        \n    public SnapshotArray(int length) {\n    }\n    \n    public void set(int index, int val) {\n        snaps.put("" + currentSnapId + "," + index, val);\n    }\n    \n    \n    public int snap(){\n        return currentSnapId++;\n    }\n    \n    public int get(int index, int snap_id) {\n        if(snap_id > currentSnapId) return 0;\n        \n        for(int i=snap_id; i >=0; i--)\n            if (snaps.containsKey("" + i + "," + index)) \n                return snaps.get("" + i + "," + index).intValue();       \n        return 0;\n    }\n}\n```
[]