Prateek sir and coding question

please elaborate the question clearly

@Narasimha,

Code modules are kept as a pile. Each module has a cost associated with it. There are two types of queries:

Query (indicated by 1):
When this module is asked for, the code module on the top of the pile is given and the student is charged according to the cost of the module.
This reduces the height of the pile by 1. In case the pile is empty, the student goes away empty-handed. (Pop operation)

Query (indicated by 2): Code module is prepared and added it on top of the pile. And reports the cost of the module. (push Operation)

Whenever student takes a module (input =1), print the price.

Now consider the following sample testcase.

7 //number of query
2 73 // 73 is cost of module, So push 73, top of the stack= 73
2 83 // 83 is cost of module, So push 83, top of the stack= 83
2 43 // 43 is cost of module, So push 43, top of the stack= 43
1 // Top of the stack= 43, So pop 43 and new top of the stack =83
Output=43
1 // Top of the stack= 83, So pop 83 and new top of the stack =73
Output=83
2 16 // 16 is cost of module, So push 16, top of the stack= 16
2 48 // 48 is cost of module, So push 48, top of the stack= 48

Now also, you can take input as:
int q = scanner.nextInt();
if(q==2)
{
int n = scanner.nextInt();
stack.push(n);
}
if(q==1)
system.out.print(stack.pop());

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.