Implementing a Priority Queue Using Heap
Ninja has been tasked with implementing a priority queue using a heap data structure. However, he is currently busy preparing for a tournament and has requested your assistance.
Your task is to use the class structure provided in the code editor comments and complete the functions: push()
, pop()
, getMaxElement()
, and isEmpty()
to implement a priority queue.
Note:
There are four types of operations that can be performed: Type 1: push(x)
- Insert element ‘x’ into the queue. Type 2: pop()
- Remove the largest element from the queue. If the queue is empty, do nothing. Type 3: getMaxElement()
- Return the largest element. If the queue is empty, return -1. Type 4: isEmpty()
- Return ‘1’ if the queue is empty, otherwise return ‘0’.
Input:
The first line contains an integer ‘Q’, the number of queries. The following lines contain the queries, each consisting of an integer indicating the type of query. For type 1 queries, there is an additional space-separated integer X.
Output:
For each type 3 query, output an integer value on a new line.
Example:
Input:
5
1 10
1 5
3
2
3
Output:
10
5
Constraints:
1 <= Q <= 100
1 <= X <= 10^9
- Time limit: 1 second
Note:
You are only required to complete the function implementations.
Be the first one to answer
Add answer anonymously...
Top Oracle Member Technical Staff interview questions & answers
Popular interview questions of Member Technical Staff
Top HR questions asked in Oracle Member Technical Staff
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app