You are viewing a single comment's thread. Return to all comments →
My Python solution. Let me know if there's a shorter way:
`def freqQuery(queries): freq = Counter() cnt = Counter() arr = [] for q in queries: if q[0]==1: cnt[freq[q[1]]]-=1 freq[q[1]]+=1 cnt[freq[q[1]]]+=1 elif q[0]==2: if freq[q[1]]>0: cnt[freq[q[1]]]-=1 freq[q[1]]-=1 cnt[freq[q[1]]]+=1 else: if cnt[q[1]]>0: arr.append(1) else: arr.append(0) return arr`
`def freqQuery(queries):
freq = Counter() cnt = Counter() arr = [] for q in queries: if q[0]==1: cnt[freq[q[1]]]-=1 freq[q[1]]+=1 cnt[freq[q[1]]]+=1 elif q[0]==2: if freq[q[1]]>0: cnt[freq[q[1]]]-=1 freq[q[1]]-=1 cnt[freq[q[1]]]+=1 else: if cnt[q[1]]>0: arr.append(1) else: arr.append(0) return arr`
Frequency Queries
You are viewing a single comment's thread. Return to all comments →
My Python solution. Let me know if there's a shorter way: