JAVA well-formatted solution
The basic idea is to have a pointer and an array of strings and move the pointer with each insert if required.\nSpace: O(n), Time: O(n)\n\n\nimport java.util.Ar
The basic idea is to have a pointer and an array of strings and move the pointer with each insert if required.\nSpace: O(n), Time: O(n)\n\n```\nimport java.util.ArrayList;\nimport java.util.List;\n\nclass OrderedStream {\n    String[] stream;\n    int ptr = 0;\n\n    public OrderedStream(int n) {\n        this.stream = new String[n];\n    }\n\n    public List<String> insert(int idKey, String value) {\n        stream[idKey - 1] = value;\n\n        List<String> result = new ArrayList<>();\n        for (int i = ptr; i < stream.length; i++) {\n            String element = this.stream[i];\n\n            if (element == null) {\n                break;\n            }\n            result.add(element);\n            ptr++;\n        }\n\n        return result;\n    }\n}\n```
['Array', 'Java']