| https://leetcode.com/problems/design-an-ordered-stream/description/ | Easy |
|---|
class OrderedStream(n: Int) {
private val stream = arrayOfNulls<String>(n + 1)
private var ptr = 1
fun insert(idKey: Int, value: String): List<String> {
stream[idKey] = value
val res = mutableListOf<String>()
while (ptr < stream.size && stream[ptr] != null) {
res.add(stream[ptr]!!)
ptr++
}
return res
}
}
/**
* Your OrderedStream object will be instantiated and called as such:
* var obj = OrderedStream(n)
* var param_1 = obj.insert(idKey,value)
*/