## fizzbuzzer.com

### Looking for good programming challenges?

Use the search below to find our solutions for selected questions!

# Frequency Queries

Sharing is caring!

Problem Statement
You are given queries. Each query is of the form two integers described below:
$1 x$ : Insert x in your data structure.
$2 y$ : Delete one occurence of y from your data structure, if present.
$3 z$ : Check if any integer is present whose frequency is exactly $z$. If yes, print 1 else 0.

The queries are given in the form of a 2-D array queries of size $q$ where queries[i][0] contains the operation, and queries[i][1] contains the data element. For example, you are given array $queries=\left[(1,1),(2,2),(3,2),(1,1),(1,1),(2,1),(3,2)\right]$. The results of each operation are:

Return an array with the output: $\left[0,1\right]$.

Function Description
Complete the freqQuery function. It must return an array of integers where each element is a $1$ if there is at least one element value with the queried number of occurrences in the current array, or $0$ if there is not.

freqQuery has the following parameter(s):

• queries: a 2-d array of integers

Input Format
The first line contains of an integer $q$, the number of queries.
Each of the next $q$ lines contains two integers denoting the 2-d array $queries$.

Constraints
* $1 \le q \le 10^6$
* $1 \le x,y,z \le 10^9$
* All $queries\left[i\right]\left[0\right] \in {1,2,3}$
* All $queries\left[i\right]\left[1\right] \le 10^9$

Output Format
Return an integer array consisting of all the outputs of queries of type $3$.

Sample Input 0

Sample Output 0

Solution