A rolling event log keeps at most C entries in a bounded FIFO buffer. Apply Q operations in order:
PUSH x - append entry value x to the back. If the buffer already holds C entries, first evict the oldest (front) entry to make room, then append.POP - remove the oldest (front) entry if the buffer is non-empty; if it is empty, do nothing.After all operations, output the remaining entries from oldest to newest.
Line 1: two integers C and Q.
Next Q lines: either PUSH x or POP.
If the buffer is empty at the end, print EMPTY. Otherwise print the remaining entries from oldest to newest, space-separated on one line.
PUSH x: -1000000000 <= x <= 1000000000Example 1
Input
2 4 PUSH 1 PUSH 2 PUSH 3 POP
Expected
3
Explanation
After PUSH 1 and PUSH 2 the buffer is [1,2]. PUSH 3 is at capacity, so 1 is evicted and 3 appended -> [2,3]. POP removes the oldest (2), leaving [3].
Example 2
Input
3 3 PUSH 5 POP POP
Expected
EMPTY
Explanation
PUSH 5 gives [5]. The first POP empties it. The second POP has nothing to remove, so the buffer stays empty -> EMPTY.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →