Stack Pop with Underflow

PHP Medium 6 views
Back to Questions

Problem Description

Process q commands: PUSH x or POP. POP prints value, but if empty prints UNDERFLOW.

Input Format

First line q. Next q lines.

Output Format

Outputs for POP.

Sample Test Case

Input:
6 POP PUSH 5 PUSH 8 POP POP POP
Output:
UNDERFLOW 8 5 UNDERFLOW

Constraints

q

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Prev Next