Min Heap implementation
Easy Accuracy: 70.71% Submissions: 7062 Points: 2

Given a priority queue (max heap) and Q queries to be performed on priority queue. The task is to perform operations based on queries.
1. p : query to push element (x, given with query) to priority_queue and print size.
2. pp : query to pop element from priority_queue and print size.
3. t : query to return top element of priority_queue, if empty -1 will be printed.

Input Format:
First line of input contains number of testcases T. For each testcase, first line of input contains Q queries. Next Q lines contains Q queries.

Output Format:
For each testcase, perform the required operation, and print if anything required.

Your Task:
Your task is to complete the functions push_pq(), pp_pq() and pq_top(), so that the queries are performed.

Constraints:
1 <= T <= 100
1 <= Q <= 100

Example:
Input:

1
5
p 5
p 3
p 1
t
pp

Output:
1
2
3
1
2

Explanation:
Testcase 1:
Pushing 5, 3, 1 to queue. Now, fetching top which is 1 (according to min heap property smallest element at top). Popping back element from queue, size reduced to 2.

to report an issue on this page.

Editorial

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

Yes

All Submissions

My Submissions:

Login to access your submissions.