You have an empty sequence, and you will be given N queries. Each query is one of these three types: 1 x -Push the element x into the stack. 2 -Delete the element present at the top of the stack. -Print the maximum element in the stack. 3 Input Format The first line of input contains an integer, N. The next N lines each contain an above mentioned query. (It guaranteed that each query is valid.) Constraints 1 ≤ N≤ 105 1 ≤ x ≤ 10⁹ 1 ≤ type ≤ 3 Output Format For each type 3 query, print the maximum element in the stack on a new line.

Systems Architecture
7th Edition
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Stephen D. Burd
Chapter7: Input/output Technology
Section: Chapter Questions
Problem 17VE
icon
Related questions
icon
Concept explainers
Question
You have an empty sequence, and you will be given N queries. Each query is one of these three types:
1 x
2
3
-Push the element x into the stack.
-Delete the element present at the top of the stack.
-Print the maximum element in the stack.
Input Format
The first line of input contains an integer, N. The next N lines each contain an above mentioned query. (It is
guaranteed that each query is valid.)
Constraints
1 ≤ N≤ 105
1 ≤ x ≤ 10⁹
1 ≤ type ≤ 3
Output Format
For each type 3 query, print the maximum element in the stack on a new line.
Transcribed Image Text:You have an empty sequence, and you will be given N queries. Each query is one of these three types: 1 x 2 3 -Push the element x into the stack. -Delete the element present at the top of the stack. -Print the maximum element in the stack. Input Format The first line of input contains an integer, N. The next N lines each contain an above mentioned query. (It is guaranteed that each query is valid.) Constraints 1 ≤ N≤ 105 1 ≤ x ≤ 10⁹ 1 ≤ type ≤ 3 Output Format For each type 3 query, print the maximum element in the stack on a new line.
Sample Input
10
1 97
WIWNEFNENP
2
1 20
2
1 26
1 20
2
3
1 91
3
Sample Output
26
91
Transcribed Image Text:Sample Input 10 1 97 WIWNEFNENP 2 1 20 2 1 26 1 20 2 3 1 91 3 Sample Output 26 91
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Types of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning