<div><p>There are <code>n</code> <code>(id, value)</code> pairs, where <code>id</code> is an integer between <code>1</code> and <code>n</code> and <code>value</code> is a string. No two pairs have the same <code>id</code>.</p>
<p>Design a stream that takes the <code>n</code> pairs in an <strong>arbitrary</strong> order, and returns the values over several calls in <strong>increasing order of their ids</strong>.</p>
<p>Implement the <code>OrderedStream</code> class:</p>
<ul>
<li><code>OrderedStream(int n)</code> Constructs the stream to take <code>n</code> values and sets a current <code>ptr</code> to <code>1</code>.</li>
<li><code>String[] insert(int id, String value)</code> Stores the new <code>(id, value)</code> pair in the stream. After storing the pair:
<ul>
<li>If the stream has stored a pair with <code>id = ptr</code>, then find the <strong>longest contiguous incrementing sequence</strong> of ids starting with <code>id = ptr</code> and return a list of the values associated with those ids <strong>in order</strong>. Then, update <code>ptr</code> to the last <code>id + 1</code>.</li>
<li>Otherwise, return an empty list.</li>
</ul>
</li>
</ul>
<p> </p>
<p><strong>Example:</strong></p>
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2020/11/10/q1.gif" style="width: 682px; height: 240px;"></strong></p>
<pre><strong>Input</strong>
["OrderedStream", "insert", "insert", "insert", "insert", "insert"]
[[5], [3, "ccccc"], [1, "aaaaa"], [2, "bbbbb"], [5, "eeeee"], [4, "ddddd"]]
<strong>Output</strong>
[null, [], ["aaaaa"], ["bbbbb", "ccccc"], [], ["ddddd", "eeeee"]]
<strong>Explanation</strong>
OrderedStream os= new OrderedStream(5);
os.insert(3, "ccccc"); // Inserts (3, "ccccc"), returns [].
os.insert(1, "aaaaa"); // Inserts (1, "aaaaa"), returns ["aaaaa"].
os.insert(2, "bbbbb"); // Inserts (2, "bbbbb"), returns ["bbbbb", "ccccc"].
os.insert(5, "eeeee"); // Inserts (5, "eeeee"), returns [].
os.insert(4, "ddddd"); // Inserts (4, "ddddd"), returns ["ddddd", "eeeee"].
</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= n <= 1000</code></li>
<li><code>1 <= id <= n</code></li>
<li><code>value.length == 5</code></li>
<li><code>value</code> consists only of lowercase letters.</li>
<li>Each call to <code>insert</code> will have a unique <code>id.</code></li>
<li>Exactly <code>n</code> calls will be made to <code>insert</code>.</li>
</ul>
</div>