谷歌面试真题:实现一个餐厅等位系统的数据结构

57次阅读
没有评论

“””
Implement a restaurant waitlist data structure. It should support the following features:

A party of customers can join the waitlist.
A previously joined party can leave the waitlist at any time.
The restaurant can ask the data structure for the first party that fits a given table size (a table size is given as an argument).
“””

这道谷歌数据结构题要求你实现一个餐厅等位系统:顾客组可以加入等位、也可以随时离开,而餐厅需要根据某个桌子的容量,快速找到队列中第一个人数不超过该容量的小组。因为既要维护加入顺序、又要支持任意位置删除和按人数查找,典型做法是用队列(维持顺序)结合哈希表(O(1) 定位并删除),再加上按人数分桶或平衡树等结构来快速找到“第一个符合的人数限制”的小组,属于典型的多数据结构组合设计题。

正文完
 0