I am looking for a data structure with which I can find the most common number (among an array of numbers) in a given variable range.
Consider the following array based on 1:
1 2 3 1 1 3 3 3 3 1 1 1 1
If I request a range (1,4), the data structure should reassign 1, which happens twice. A few other examples:
(1,13) = 1
(4.9) = 3
(2,2) = 2
(1,3) = 1 (all 1,2,3 meet once, therefore we return the first / smallest, not so important at the moment)
I searched, but did not find anything like it. I am looking for (ideally) a data structure with minimal space requirements, fast preprocessing and / or query complexity.
Thanks in advance!