Algorithm interview from Google

前端 未结 8 469
囚心锁ツ
囚心锁ツ 2021-01-30 11:55

I am a long time lurker, and just had an interview with Google where they asked me this question:

Various artists want to perform at the Royal Albert Hall and you are re

8条回答
  •  无人及你
    2021-01-30 12:37

    You need a normal binary search tree of intervals of available dates. Just search for the interval containing d. If it does not exist, take the interval next (in-order) to the point where the search stopped.

    Note: contiguous intervals must be fused together in a single node. For example: the available-dates intervals {2 - 15} and {16 - 23} should become {2 - 23}. This might happen if a concert reservation was cancelled.

    Alternatively, a tree of non-available dates can be used instead, provided that contiguous non-available intervals are fused together.

提交回复
热议问题