Skip to content

Instantly share code, notes, and snippets.

@imedadel
Created November 3, 2019 18:31
Show Gist options
  • Select an option

  • Save imedadel/b2d0f36cbd90dc2c81e38be019f2d424 to your computer and use it in GitHub Desktop.

Select an option

Save imedadel/b2d0f36cbd90dc2c81e38be019f2d424 to your computer and use it in GitHub Desktop.
from collections import Counter
def freqQuery(queries):
items = Counter()
checks = Counter()
res = []
for couple in queries:
query, item = couple
if query == 1:
checks[items[item]] -= 1
items[item] += 1
checks[items[item]] += 1
elif query == 2:
if checks[item] > 0:
checks[items[item]] -= 1
items[item] -= 1
checks[items[item]] += 1
else:
if checks[item] > 0:
res.append(1)
else:
res.append(0)
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment