You are viewing a single comment's thread. Return to all comments →
def freqQuery(queries): ans = [] fMap = defaultdict(int) cMap = defaultdict(int) for op, num in queries: if op == 1: count = fMap[num] fMap[num] += 1 cMap[count] -= 1 cMap[count+1] += 1 elif op == 2: count = fMap[num] if count > 0: fMap[num] -= 1 cMap[count] -= 1 cMap[count-1] += 1 else: ans.append(int(cMap[num] > 0)) return ans
Seems like cookies are disabled on this browser, please enable them to open this website
Frequency Queries
You are viewing a single comment's thread. Return to all comments →