C++ | T: O(n), S: O(n) | Vector approach
\nclass OrderedStream final {\npublic:\n    explicit OrderedStream() noexcept = default;\n    explicit OrderedStream(const OrderedStream&) noexcept = default;\n
```\nclass OrderedStream final {\npublic:\n    explicit OrderedStream() noexcept = default;\n    explicit OrderedStream(const OrderedStream&) noexcept = default;\n\n    OrderedStream(int n) : stream_(std::vector<std::string>(n, "")), current_index_(0) {}\n\n    std::vector<std::string> insert(int id, std::string value) {\n        std::vector<std::string> response;\n        stream_[id - 1] = std::move(value);\n\n        for (; current_index_ < stream_.size(); ++current_index_) {\n            if (!stream_[current_index_].empty()) {\n                response.push_back(stream_[current_index_]);\n            } else {\n                break;\n            }\n        }\n\n        return response;\n    }\n\nprivate:\n    std::vector<std::string> stream_;\n    int current_index_;\n};\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * OrderedStream* obj = new OrderedStream(n);\n * vector<string> param_1 = obj->insert(id,value);\n */\n\n```
[]