86ms Beats 94.33% of users with C++
Intuition\nThe problem involves designing a data structure to handle an ordered stream of strings. My initial thoughts are to use a vector to store the strings 
# Intuition\nThe problem involves designing a data structure to handle an ordered stream of strings. My initial thoughts are to use a vector to store the strings and a pointer to keep track of the current position in the stream.\n\n# Approach\n1. **Initialization:**\n   - Create a vector `data` to store the strings. The size of the vector is set to `n + 1` to allow for 1-based indexing.\n   - Initialize a pointer `ptr` to 1, indicating the starting position in the stream.\n\n2. **Insert Operation:**\n   - In the `insert` method, update the `data` vector at the specified index (`id`) with the given value.\n   - After updating, check the subsequent positions in the vector. If they contain non-empty strings, add them to the result vector and update the pointer.\n\n3. **Return Result:**\n   - Return the result vector containing the strings encountered in the stream.\n\n# Complexity\n- Time complexity:\n  - The `insert` operation has a time complexity of $$O(1)$$ for updating the vector at a specific index.\n  - The overall time complexity depends on the number of non-empty strings encountered in the stream.\n\n- Space complexity:\n  - The space complexity is $$O(n)$$, where $$n$$ is the size of the vector used to store the strings in the stream.\n# Code\n```\nclass OrderedStream {\nprivate:\n    vector<string> data;\n    int ptr;\n\npublic:\n    OrderedStream(int n) {\n        data.resize(n + 1);\n        ptr = 1;\n    }\n    vector<string> insert(int id, string value)\n    {\n        data[id]=value;\n        vector<string> ans;        \n        while(ptr<data.size()&&!data[ptr].empty())\n        {\n            ans.push_back(data[ptr]);\n            ptr++;\n        }\n\n        return ans;\n    }\n};\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(idKey,value);\n */\n```
['Array', 'Hash Table', 'Design', 'Data Stream', 'C++']