C++ solution with explanation
\nclass OrderedStream {\nprivate:\n    std::vector<string> stream;\n    int readIdx;\n    \npublic:\n    OrderedStream(int n) {\n        // resize the vector st
```\nclass OrderedStream {\nprivate:\n    std::vector<string> stream;\n    int readIdx;\n    \npublic:\n    OrderedStream(int n) {\n        // resize the vector stream\n        stream.resize(n);\n        // Initialize the readIdx to starting point\n        readIdx = 0;        \n    }\n    \n    vector<string> insert(int idKey, string value) {\n        // Insert the value at specified index\n        stream[idKey-1] = value;\n               \n        // Current string at readidx is filled, need to return\n        // the longest possible chunk. Loop all the values of\n        // the stream starting from read idx and append it to\n        // result only if it is not empty or reaches an index\n        // where the string is empty\n        int start = readIdx;\n        while(readIdx < stream.size() && !stream[readIdx].empty()) {\n            // String is inserted at this read Idx, increament the\n            // readIdx and numelem\n            readIdx++;\n        }\n        \n        return vector<string>(stream.begin()+start, stream.begin()+readIdx);\n    }\n};\n```
[]