-2

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..??

Harsh Agarwal
  • 25
  • 1
  • 6

1 Answers1

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