ORIGINAL CODING QUESTION
Front after queue commands
Each command pair is (1,x) to enqueue x or (2,0) to remove the front if present. Return the final front, or -101 for an empty queue.
Original exercise · easy. Editorial role relevance does not imply a company has asked this question.
Input and output
q, followed by q command/value pairs.
Constraints
1 ≤ q ≤ 200; enqueued values -100..100; dequeue commands use value 0.
Example 1
Input
4 1 5 1 8 2 0 1 9
Output
8
The final front is 8.
Example 2
Input
1 2 0
Output
-101
The queue remains empty.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
Maintain FIFO order.
Hint 2
Removing from an empty queue does nothing.
Hint 3
A head index avoids repeatedly shifting all remaining values.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →