Given an array of numbers a[0], a[1], ..., a[n-1], we get queries of the kind:
a[0], a[1], ..., a[n-1]
output k-th largest number in the range a[i], a[i+1],
k
a[i], a[i+1],
There is an algoritm named QuickSelect which based on quick sort. It works O(n) in average case. Algorithm's worst case is O(n**2) when input revese ordered.
It gives exact k-th biggest number. If you want range, you can write an wrapper method.