Algorithm interview from Google

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

    Why not try to use Union-Find? You can group each concert day + the next 5 days as part of one set and then perform a FIND on the given day which would return the next set ID which would be your next concert date.

    If implemented using a tree, this gives a O(log n) time complexity.

提交回复
热议问题