Indian Computing Olympiad

Training Material


Range Queries→Longest open segment

There are N plots arranged in a sequence 1..N. As time goes by, these plots are sold, one at a time. Periodically, you have to report the longest unsold segment of plots.

For instance, if N = 15 and you get the instructions

  sell(3)
  sell(8)
  sell(7)
  sell(15)
  report()
      

the answer is 6, which is the length of the empty interval [9,14].

Solution