class OrderedStream {
private map: Map<number, string>
private turn: number
constructor(n: number) {
this.map = new Map()
this.turn = 1
}
insert(idKey: number, value: string): string[] {
this.map.set(idKey, value)
if (idKey !== this.turn) return []
const result = []
while (this.map.has(this.turn)) {
result.push(this.map.get(this.turn))
this.map.delete(this.turn)
this.turn++
}
return result
}
}