Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Queue Front After Operations

Queuesmedium

Implement `queueFront(ops)` where each op is `{ type: 'enq', val }` or `{ type: 'deq' }`. Apply them and return the value at the front, or `null` if empty.

Sample tests

Input: queueFront([{"type":"enq","val":1},{"type":"enq","val":2},{"type":"deq"}])
Output: 2
Input: queueFront([{"type":"enq","val":5}])
Output: 5

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Dequeuing an empty queue should be a safe no-op.

Learning resources

  • Wikipedia: Data structure
Approach & explanation (try first)

Replaying the operations on an array models a queue; the front is the first element or null when empty.

Loading...
⌘/Ctrl + Enter

Run your code to see results.