Given an array A indexed from 0 to n-1 , where n is the size of the array, and a series of queries of the form ij , where i and j indicate the indices ( i and j inclusive), how do you know which index was the largest number of queries more efficient?
For example, consider an array [3,4,5,6,7,9]
And requests
0 3 3 5 1 2 2 4 Output Index 0 has been queried 1 time. Index 1 has been queried 2 times. Index 2 has been queried 3 times. Index 3 has been queried 3 times. Index 4 has been queried 2 times. Index 5 has been queried 1 time.
How to do it as quickly as possible?
source share