Snapshot-Array(JAVA) Using Tree Map Easy to Understand Beats 69.9% 🔥🧑🏽‍💻🌐
Intuition\n Describe your first thoughts on how to solve this problem. \nSimply follow the question accordingly.. whatever we have to implement in a function.. 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSimply follow the question accordingly.. whatever we have to implement in a function.. Mapping is a perfect choice but which one? That\'s your presence of mind.\uD83E\uDD2F\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nDefined a TreeMap where we can store key-val pair in a sorting order. Approach for following functions are:\n\n    SnapshotArray(int length) function all value upto length with value (0,0);\n\n    In set(index, val) function simply using TreeMap method put to set value at a particular index.\n\n    In snap() returned the incremented value snap_id++;\n\n    Int get(index, snap_id) function returned the flootEntry of snap_id from the desired index value.. \n\n**floorEntry(): It returns a key-value mapping associated with the greatest key less than or equal to the given key, or null if there is no such key.**\n(POV: Review code for more clearity)\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    O(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    O(n^2)\n**Thank You For reviewing my code... PLEASE UPVOTE!\uD83D\uDC40**\n\n# Code\n```\nclass SnapshotArray {\n    private int snap_id;\n    private TreeMap<Integer,Integer>[] snapshotArray;\n\n    public SnapshotArray(int length) {\n        snap_id = 0;\n        snapshotArray = new TreeMap[length];\n        for(int i=0; i<length; i++){\n            snapshotArray[i]=new TreeMap<>();\n            snapshotArray[i].put(0,0);\n        }\n    }\n    \n    public void set(int index, int val) {\n        snapshotArray[index].put(snap_id,val);\n    }\n    \n    public int snap() {\n        return snap_id++;\n    }\n    \n    public int get(int index, int snap_id) {\n        return snapshotArray[index].floorEntry(snap_id).getValue();\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```
['Array', 'Java']