Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6380 |

@mb1973 | 5642 |

@Quandray | 5233 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3413 |

Complete Leaderboard | |

Handle | Score |

@sanskar94511 | 537 |

@akashverma4 | 291 |

@swastik8750 | 237 |

@nishunishuraj18 | 223 |

@nayan2709 | 211 |

@ajaybhardwaj1999 | 196 |

@surajmamgai | 193 |

@AnshikaPandey | 192 |

@gurshehzadsingh | 188 |

@Rajpra786 | 185 |

@shardul08 | 185 |

Complete Leaderboard |

Geek has several competitive programming books and he wants to place books one on another (like a stack). There are total Q queries of two types.

**Type 1:** This query is represented by **"place x", **where x is an integer represents a number of the book geek wants to place on the top of the stack.

**Type 2:** This query is represented by **"remove". **After** **this query, print a book number which is at the top of the stack (If the stack is empty then print -1) and remove it from the stack.

**Note:** There can be multiple books with the same number.

**Input: **

1. The first line of the input contains a single integer* * **T** denoting the number of test cases. The description of **T** test cases follows.

2. The first line of each test case contains a single integer** Q****.**

3. The next Q lines contain queries

**Output:** For each test case, for each query of type 2, print the top book number of the stack (space separated)

**Constraints:**

1. 1 <= T <= 100

2. 1 <= Q <= 10^{4}

3. 1 <= x <= 10^{9}

**Example:
Input:**

2

5

place 6

place 2

remove

place 3

remove

3

remove

place 5

remove

**Output:**

2 3

-1 5

**Explanation:**

**Test Case 1:** String has an equal number of ones and zeros and at each index(starting from left) the number of occurrences of **0's** is greater than or equals to the number of occurrences **1's**.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Geek and Books

...