Input: N = 5, num = 3, A = {1, 1, 3, 4, 3}, Q = {{0, 2, 2}, {0, 2, 1}, {0, 4, 2}}
Output: 2 1 2
Explanation: For query 1: L = 0, R = 2, K = 2, let L ≤ i ≤ R
- For i = 0: frequency of a[i] i.e. 1 from i to n-1 is 2.
- For i = 1: frequency of a[i] i.e. 1 from i to n-1 is 1.
- For i = 2: frequency of a[i] i.e. 3 from i to n-1 is 2.
- Hence we have two elements from index 0 to 2 whose frequency from i to n-1 is 2.
For query 2: L = 0, R = 2, K = 1
As we can see from the above query that there is only a single element in 0 to 2 whose frequency from i to n-1 is 1.
For query 3: L = 0, R = 4, K = 2
The answer will be 2 because of the index 0 and 2.
Input: N = 5, num = 2, A = {1, 1, 1, 1, 1}, Q = {{0, 4, 2}, {0, 4, 1}}
Output: 1 1
Explanation: For query 1: L = 0, R = 4, K = 4, let L ≤ i ≤ R
- For i = 0: frequency of a[i] i.e. 1 from i to n-1 is 5.
- For i = 1: frequency of a[i] i.e. 1 from i to n-1 is 4.
- For i = 2: frequency of a[i] i.e. 1 from i to n-1 is 3.
- For i = 3: frequency of a[i] i.e. 1 from i to n-1 is 2.
- For i = 4: frequency of a[i] i.e. 1 from i to n-1 is 1.
- Hence we have one elements from index 0 to 4 whose frequency from i to n-1 is 2.
Similarly, For query 2: there is only 1 element in 0 to 4 whose frequency from i to n-1 is 1.