Frequency Queries

  • + 0 comments
    def freqQuery(queries):
        freq_map = {}
        result = []
         
        for query in queries:
            operation, element = query
            
            if operation == 1:
                freq_map.setdefault(element, 0)
                freq_map[element] += 1
                
            elif operation == 2 and freq_map.get(element):
                freq_map[element] -= 1
                
            elif operation == 3:
                matched = element in freq_map.values()
                result.append(1) if matched else result.append(0)
                
        return result