✅Simple C++ || Binary search With comments ||
typedef pair pii;\n\nclass SnapshotArray {\n    \nprivate:\n    \n    int n = 0;\n    vector> m;\n    \npublic:\n    \n    \n    SnapshotArray(int length) {\n  
typedef pair<int,int> pii;\n\nclass SnapshotArray {\n    \nprivate:\n    \n    int n = 0;\n    vector<vector<pii>> m;\n    \npublic:\n    \n    \n    SnapshotArray(int length) {\n        m = vector<vector<pii>>(length, vector<pii>(1, {0 , 0})); // every element is 0 in beginning\n    }\n    \n    void set(int index, int val) {\n        \n        int x = m[index].size();\n        \n        if(m[index][x-1].second == n)   // if no new snaps were taken after last entry\n            m[index][x-1].first = val;  // then update the last entry\n        else \n            m[index].push_back({val , n});       // else make a new entry with new snap_id\n        \n    }\n    \n    int snap() {\n        n++;\n        return n-1;\n    }\n    \n    int get(int index, int snap_id) {\n        \n        int l = 0, h = m[index].size()-1;\n        \n        while(l <= h){                 // binary search for first index with snap_id equal or lower\n            \n            int mid = l+(h-l)/2;\n            \n            if(m[index][mid].second == snap_id)\n                return m[index][mid].first;\n            else if(m[index][mid].second > snap_id)\n                h = mid-1;\n            else \n                l = mid+1;\n            \n        }\n        \n        return m[index][h].first;\n    }\n};\n
['C', 'Binary Tree', 'C++']