function solution(operations) {
let answer = [0, 0];
let queue = [];
for (const op of operations) {
const [command, num] = op.split(' ');
if (command === 'I') queue.push(+num);
else if (command === 'D') {
if (num === '-1') queue.splice(queue.indexOf(Math.min(...queue)), 1);
else queue.splice(queue.indexOf(Math.max(...queue)), 1);
}
}
return queue.length === 0 ? [0, 0] : [Math.max(...queue), Math.min(...queue)];
}