Given an array of integers and queries, each query asks: what is the most frequent value in range ? If there are ties, return any. Constraints: .
This is trickier than distinct values. Adding an element might change the mode. Removing an element might also change it.
Think about what data structures you need to track both the frequency of each value and which value has the highest frequency. Can you do add/remove in ?