Frequency Queries

  • + 1 comment

    My question is why is this better than using a defaultdict and a Counter? my solution is as follows:

    def freqQuery(queries):
        occ_dict = defaultdict(int)
        result_array = []
        for op in queries:
            if op[0] == 1:
                occ_dict[op[1]] += 1
            elif op[0] == 2:
                if occ_dict[op[1]] > 0:
                    occ_dict[op[1]] -= 1
            elif op[0] == 3:
                occ_counter = Counter(occ_dict)
                if occ_counter[op[1]]:
                    result_array.append(1)
                else:
                    result_array.append(0)
        return(result_array)
    

    Any help would be appreciated, thanks!