leetcode.com/contest/weekly-contest-215
Contest - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
class OrderedStream { String[] streamList; int ptr; public OrderedStream(int n) { streamList = new String[n]; ptr = 0; } public List<String> insert(int id, String value) { streamList[id - 1] = value; ArrayList<String> orderedStreams = new ArrayList<String>(); for (int i=ptr; i<streamList.length; i++) { if (streamList[i] == null) break; orderedStreams.add(streamList[i]); ptr++; } return orderedStreams; } }