Java TreeMap snap() O(1) set()/get() O(log(50_000))
Time: \n\tconstruct: O(1), snap(): O(1), set(): O(log(50_000), get(): O(log(50_000).\nSpace:\n\tO(number of calls to set()).\n\nclass SnapshotArray {\n    \n   
Time: \n\tconstruct: O(1), snap(): O(1), set(): O(log(50_000), get(): O(log(50_000).\nSpace:\n\tO(number of calls to set()).\n```\nclass SnapshotArray {\n    \n    TreeMap<Long, Integer> map = new TreeMap<>();\n    final long asked = 50_001;\n    int snapShots = 0;\n\n    public SnapshotArray(int length) {}\n    \n    public void set(int index, int val) {\n        \n        long key = index * asked + snapShots;\n        \n        map.put(key, val);\n    }\n    \n    public int snap() {\n        \n        return ++snapShots - 1;\n    }\n    \n    public int get(int index, int snap_id) {\n        \n        Long key = map.floorKey(asked * index + snap_id);\n        \n        if(key == null || key < asked * index)\n            return 0;\n        \n        return map.get(key);\n    }\n}\n```
[]