Created
November 3, 2019 18:31
-
-
Save imedadel/b2d0f36cbd90dc2c81e38be019f2d424 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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