Continuing this question: Job Interview Question Using Trees, What data to save?
Now, I am looking for an algorithm that does the following:
IsWorstSince(d1,d2)
: check wither d2 is the day with most new infected people since d1. Return:
false
if there is one day between both days such that the number of infected people in that day is bigger than d2.
true
, If we can verify for sure that from all days between d1 and d2 (Not only those who were inserted) none has bigger number of infected people than d2.
unknown
, if there is some data missing, For example if some days weren't inserted into the data structure.
Time Complexity: O(log n)
We can assume that d1<d2 and that both days do exist in the data structure.
I think this question is really related to the previous one. but not sure how to use it.
Note: In the previous one we implemented WorseBefore(d) that return the last day (between those which were inserted to the DS) before d which had more infected people than there is in day d.