A notification center receives a stream of commands. "push P ID" adds a notification with priority P (a whole number; smaller is more urgent) and id ID. "pop" shows the most urgent waiting notification and removes it. Among equal priorities, the one pushed earlier is shown first.
Write drain(commands) that runs the commands in order and returns the ids shown by each "pop", in order. A "pop" when nothing is waiting shows "none".
Input: commands = ["push 2 email","push 1 alert","pop","push 1 chat","pop","pop"] Output: ["alert","chat","email"]
alert (1) beats email (2); then chat (1) beats email.
Input: commands = ["pop","push 5 a","push 5 b","pop"] Output: ["none","a"]
Nothing is waiting at first. Then a and b tie, and a was pushed first.
1 <= commands.length <= 10^4-10^6 <= P <= 10^6Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #397 Drain the Notification Queue. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.