An upload manager keeps pending file sizes in a first-in-first-out queue and shows the largest pending size. Write a class MaxQueue:
enqueue(size) adds a size at the back.dequeue() removes and returns the oldest size, or -1 if the queue is empty.max() returns the largest size in the queue, or -1 if it is empty.Each call should take O(1) time on average.
Each example lists the calls in order, then each call's arguments. The first call creates the object with new MaxQueue(…); the output lists what each call returns (null for the constructor and for methods that return nothing).
Input: ["MaxQueue","enqueue","enqueue","enqueue","max","dequeue","max","dequeue","max"] [[],[3],[9],[4],[],[],[],[],[]] Output: [null,null,null,null,9,3,9,9,4]
9 is the largest until it leaves; then only 4 is left.
Input: ["MaxQueue","max","dequeue"] [[],[],[]] Output: [null,-1,-1]
An empty queue answers -1 to both.
1 <= size <= 10^510^4 calls.Run 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 #278 Queue With Running Maximum. 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.