You are viewing a single comment's thread. Return to all comments →
First Python Solution
def freqQuery(queries): results = [] freq = {} CONST_ACTION = 0 CONST_VALUE = 1 INSERT_ELEMENT = 1 REMOVE_ELEMENT = 2 CONST_FIND_ELEMENT = 3 for query in queries: action = query[CONST_ACTION] key = query[CONST_VALUE] if action in (INSERT_ELEMENT, REMOVE_ELEMENT): if key in freq: freq[key] += 1 if action == INSERT_ELEMENT else (-1 if freq[key] != 0 else 0) else: if action == INSERT_ELEMENT: freq.setdefault(key, 1) else: results.append(int(key in set(freq.values()))) 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 →
First Python Solution