We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I learned from Google AI, but I think I improved upon it :)
import heapq
myheap = []
heapq.heapify(myheap)
Q = int(input())
valid = set()
for _ in range(Q):
command = [int(i) for i in input().split(' ')]
if command[0] == 1:
heapq.heappush(myheap, command[1])
valid.add(command[1])
elif command[0] == 2:
valid.remove(command[1])
elif command[0] == 3:
while True:
ans = myheap[0]
if ans in valid:
print(ans)
break
else:
heapq.heappop(myheap)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
QHEAP1
You are viewing a single comment's thread. Return to all comments →
I learned from Google AI, but I think I improved upon it :)
import heapq
myheap = [] heapq.heapify(myheap)
Q = int(input()) valid = set()
for _ in range(Q):