algorithm - Number of Ranges that lie completely in a particular Range -
let have n ranges each specified by
[l_i,r_i] 1<=i<=n and have query of type [l,r] in have find number of ranges among n ranges lie completely in given range i.e. [l,r]
example:
n ranges are:
here n 2.
2 4 3 3 for query 3 5, output should 1.
for query 2 5 output should 2.
i know method o(m*n), n number of ranges , m number of queries, feels there must more efficient implementation.
yes, there is. data structure want called interval tree.
Comments
Post a Comment