Amazon interview question

Priority queue and stacks leetcode