Simulate stream to output result in correct sequence, provide solution to avoid memory leaking. Input seqeuence is 1, 2, 4, 5, 3, 6 Output seqeuence is 1, 2, 3, 4, 5 ,6
Sigiloso
Simulation: 1, 2 just output, 4, 5 push to memory, 3 just output, pull out 4 and 5 out of memory and output, 6 just output. Use Hash Set as memory for O(1) operation cost.