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.
Why this works? .pop() removes an element randomly. But hackrrank assumes always min element is removed.
n=int(input())s=set(map(int,input().split()))N=int(input())for_inrange(N):cmd=input().split()ifcmd[0]=='pop':# remove the smallest item to match HackerRank's pop behaviors.remove(min(s))elifcmd[0]=='remove':s.remove(int(cmd[1]))elifcmd[0]=='discard':s.discard(int(cmd[1]))print(sum(s))
Set .discard(), .remove() & .pop()
You are viewing a single comment's thread. Return to all comments →
Why this works? .pop() removes an element randomly. But hackrrank assumes always min element is removed.