Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
The queries must be answered efficiently to avoid time limit exceeded verdict.
Store the elements of the array in a data structure that helps answering the queries efficiently.
Use a hash table that stored for each value, the indices where that value appeared.
Use binary search over the indices of a value to find its range frequency.