I know a similar question exists here. My question is also same that I have N intervals (some possibly overlapping some even same). Then Q point queries are given and I need to tell how many intervals contains this point.
I tried to develop my algorithm by sorting the end point array then counting the number of overlapped interval by +1, -1 trick as mentioned in an answer. But after performing the binary search what I should do? Because its not always the case that the corresponding index of the prefix sum array is the answer.
e.g.
Intervals are : [1,4] [5,7] [6,10] [7,13]
sorted end point array : [1,4,5,6,7,7,10,13]
+1/-1 array : [1,-1,1,1,1,-1,-1,-1]
prefix sum array : [1,0,1,2,3,2,1,0]
Query : 10
my algorithm gives 1 (corresponding prefix array)
but actual ans should be 2.
How should I fix my algorithm?