You are viewing a single comment's thread. Return to all comments →
nice work!
i ended up with something almost identical, though i used defaultdicts with sets
def freqQuery(queries): results = [] lookup = dict() freqs = defaultdict(set) for command, value in queries: freq = lookup.get(value, 0) if command == 1: lookup[value] = freq + 1 freqs[freq].discard(value) freqs[freq + 1].add(value) elif command == 2: lookup[value] = max(0, freq - 1) freqs[freq].discard(value) freqs[freq - 1].add(value) elif command == 3: results.append(1 if freqs[value] else 0) return results
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 →
nice work!
i ended up with something almost identical, though i used defaultdicts with sets