best solution in java
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass SnapshotArray {\n\n TreeMap<Integer, Integer>[] snapshotArray;\n int snap_id;\n\n public SnapshotArray(int length) {\n     this.snapshotArray = new TreeMap[length];\n     this.snap_id = 0;\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/**\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```
['Java']