Algorithm interview from Google

前端 未结 8 747
囚心锁ツ
囚心锁ツ 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:35

    It was already mentioned above, but basically keep it simple with a binary tree. You know a binary tree has log N complexity. So you already know what algorithm you need to use. All you have to do is to come up with a tree node structure and use binary tree insertion algorithm to find next available date: A possible one: The tree node has two attributes: d (date of the concert) and d+5 (end date for the blocking period of 5 days). Again to keep it simple, use a timestamp for the two date attributes. Now it is trivial to find next available date by using binary tree inorder insertion algorithm with initial condition of root = null.

提交回复
热议问题