Account
Draft saved on this device
▤ DescriptionOriginal CppValley problem
ConcurrencyMedium

Implement a Bounded Ring Buffer Simulator

Model a fixed-capacity FIFO buffer, including full and empty behavior.

Implement a sequential reference model of a bounded FIFO ring buffer. PUSH x inserts x if there is room; otherwise print FULL. POP prints and removes the oldest element, or prints EMPTY when no element is available. Do not confuse this reference model with a thread-safe SPSC implementation; the latter requires additional concurrency reasoning.

Input format

First line: capacity N and number of commands Q. Next Q lines: PUSH x or POP.

Output format

Print a line for every POP and every rejected PUSH, in command order.

Examples

Example 1
Input
2 6
PUSH 7
PUSH 8
PUSH 9
POP
POP
POP
Expected output
FULL
7
8
EMPTY

Constraints

  • 1 ≤ N ≤ 100000
  • 1 ≤ Q ≤ 100000
  • -10^9 ≤ x ≤ 10^9

Related concepts

Ring BufferQueuesData Structures

This early-access exercise uses standard input/output. More advanced concurrency challenges will use specialized class interfaces, instrumentation, and stress tests once the judging infrastructure is ready.

⌘ CodeC++17
GNU C++17 · main.cpp

Loading Monaco C++ editor…

Checking judge...

Checking whether the external C++ judge is available.

⌁ Test cases & resultsPublic samples: 1
Input
2 6
PUSH 7
PUSH 8
PUSH 9
POP
POP
POP
Expected output
FULL
7
8
EMPTY
Execution requires a secure external judge.