leetle

Daily challenge for 2026-04-02

457. Simple Queue Element Tracking

You are given an array of integers operations representing a sequence of operations on a queue. A positive integer x means enqueue x. A value of -1 means dequeue the front element. If the queue is empty and a dequeue operation occurs, nothing happens. Return the sum of all elements that were successfully dequeued during the entire sequence of operations. The queue should be processed in FIFO order.

Example:
Input: operations = [10, 20, -1, 30, -1, -1, 5]
Output: 60

Explanation: Enqueue 10 and 20, dequeue 10, enqueue 30, then dequeue 20 and 30. The successful dequeues are 10, 20, and 30, so the total is 60.

Run this challenge interactively in Python or JavaScript when the app loads.