function solution(operations) {
let arr = []
let op = operations.map((el) => el.split(" "))
op.forEach((el) => {
if(el[0] === "I"){
arr.push(Number(el[1]))
} else {
let num = (el[1] === "1" ? Math.max : Math.min)(...arr)
let idx = arr.indexOf(num)
arr.splice(idx , 1)
}
})
return arr.length ? [Math.max(...arr),Math.min(...arr)] : [0,0]
}
원래 출제 의도대로라면 힙(Heap)을 사용하여 풀어야 하지만, JS 특성상 힙을 직접 구현해야하기 때문에 다르게 풀었다.