[C++] elegant solution
It is quite hard to understand the requirements at first, but the animation makes it easier.\nSo, we know in advance that we will be having an array of strings 
It is quite hard to understand the requirements at first, but the animation makes it easier.\nSo, we know in advance that we will be having an array of strings of length *n*, and therefore\nthe constructor allocates a vector of empty strings. That is quite easy.\n\nInserting a value is also easy, since it is guaranteed, by the problem description, that each pair\nwill have a unique *id*. You just replace the empty string on a position given by *idKey* (-1, since\nwe count from 0) with string *value*.\n\nNow comes the tricky part. Upon each insertion, you need to return a list of strings such that it\nis a continuos chunk, with no empty strings between them. You start off from index *lastIndex*, and in a \naux buffer you *push_back* all non-empty strings that come afterwards, and you increment *lastIndex*\nafter each push. Also, pay attention that you cannot check *arr.at(lastIndex)* if *lastIndex* is out of range.\nThat will throw you a runtime error which is hard to figure out. That\'s why you need *lastIndex < arr.size()*.\n\nNo dynamic allocation, so no destructor is needed.\n\n\n```\nclass OrderedStream {\npublic:\n    OrderedStream(int n) : arr {vector<string>(n, "")} \n    {\n    }\n    \n    vector<string> insert(int idKey, string value) \n    {\n        arr.at(idKey-1) = value;  \n        \n        vector<string> ret{};\n        \n        while (lastIndex < arr.size() && arr.at(lastIndex) != "")\n        {\n            ret.push_back(arr.at(lastIndex++));\n        }\n        \n        return ret;\n    }\n    \nprivate:\n    vector<string> arr;\n    int lastIndex{0};\n};\n```\n\nThanks to [@RedaKerouicha](https://leetcode.com/RedaKerouicha) for pointing out that *vector<string> arr{};* should be *vector<string> arr;* since we initialize it in the constructor.\n
['C', 'C++']