Given an array(unsorted) of n integers and an integer 'X'. We are also given a range (low,high). How can we find the number of occurrences of 'X' in the range (low,high). Can we do it by Segment tree..??
Asked
Active
Viewed 50 times
-2
-
What programming language? – blueygh2 Mar 12 '14 at 22:45
1 Answers
0
As the array is unsorted you need to iterate through the whole array at least once. Therefore there is no better solution than to iterate through the whole array and just count the occurrences of 'X'. The solution requires O(n) time and O(1) memory.
Regards, Damjan

Damjan Dakic
- 265
- 1
- 19