Frequency Queries
Solutions Warning: the problem I/O might result slow. For some languages (e.g. C++), it’s better off reading the whole input first.
This problem requires some additional storage to be solved efficiently. Using only one hash map is not enough because of operation of type 3.
The idea is to use a hash map to store the frequencies of each element (query type 1 and 2) and also an additional hash map “histogram”, that is an inverse map from frequency to elements having such a frequency.
[Read More]