Get min at pop
Submissions: 4697   Accuracy:

57.19%

  Difficulty: Easy   Marks: 2

Now, we'll try to solve a famous stack problem.

You are given an array A of size N. You need to push the elements of the array into a stack and then print minimum in the stack at each pop.

Input Format:
The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains two lines of input. The first line of input contains size of array N. The second line of array contains the elements of array separated by spaces.

Output Format:
For each testcase, in a new line, print the required output.

Your Task:
Since this is a function problem, you don't need to take any input. Just complete the provided functions _push() and _getMinAtPop().

Constraints:
1 <= T <= 100
1 <= Ai <= 107

Examples:
Input:

2
5
1 2 3 4 5
7
1 6 43 1 2 0 5

Output:
1 1 1 1 1
0 0 1 1 1 1 1

Explanation:
Testcase 1:
 After pushing elements to the stack, the stack will be top --- > 5, 4, 3, 2, 1. Now, start popping elements from stack:
popping 5: min in the stack is 1. popped 5
popping 4: min in the stack is 1. popped 4
popping 3: min in the stack is 1. popped 3
popping 2: min in the stack is 1. popped 2
popping 1: min in the stack is 1. popped 1.

 

** For More Input/Output Examples Use 'Expected Output' option **

Author: Soul_xhacker


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.