Skip to content

Instantly share code, notes, and snippets.

@amulyakashyap09
Created December 31, 2017 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amulyakashyap09/f16c4c189621b72eae4bd97d1e4641c8 to your computer and use it in GitHub Desktop.
Save amulyakashyap09/f16c4c189621b72eae4bd97d1e4641c8 to your computer and use it in GitHub Desktop.
Set remove, discard, pop problem | hackerrank
n = int(input())
s = set(map(int, input().split()))
o = int(input())
for i in range(o):
op = input().split()
if(op[0] == "pop"):
if len(s)>0:
s.pop()
elif(op[0] == "remove"):
if int(op[1]) in s:
s.remove(int(op[1]))
elif(op[0] == "discard"):
s.discard(int(op[1]))
else:
assert False
print(sum(s))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment