🔥🔥C++ Solution || ✅✅ Using vector of map
\n\n# Code\n\nclass SnapshotArray {\npublic:\n   int snapNo=0;\n   vector<map<int,int>> ar;\n\n    SnapshotArray(int length) {\n        ar.resize(length);\n    
\n\n# Code\n```\nclass SnapshotArray {\npublic:\n   int snapNo=0;\n   vector<map<int,int>> ar;\n\n    SnapshotArray(int length) {\n        ar.resize(length);\n        for(int i=0;i<length;i++){\n            ar[i][0]=0;\n        }\n    }\n    \n    void set(int index, int val) {\n        \n        ar[index][snapNo]=val;\n    }\n    \n    int snap() {\n        snapNo++;\n        return snapNo-1;\n    }\n    \n    int get(int index, int snap_id) {\n    // we will check that if a given snap_id exists in a snapshot\n    // ar[index] and returns the value associated with that snap_id\n    //  if found. If the snap_id is not present, it returns the \n    //  closest value that is less than the snap_id from the\n    //  previous snapshots.\n      if(ar[index].find(snap_id)==ar[index].end()){\n\n          auto i= --ar[index].lower_bound(snap_id);\n          return i->second;\n      }\n        return ar[index][snap_id];\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', 'C++']