Created
December 31, 2017 16:23
-
-
Save amulyakashyap09/f16c4c189621b72eae4bd97d1e4641c8 to your computer and use it in GitHub Desktop.
Set remove, discard, pop problem | hackerrank
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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