DoorDash VO 面试题解析:Dasher 最小负载容量(Binary Search + 贪心分配)

86次阅读
没有评论

You are given a 0-indexed integer array representing the number of orders for each restaurant.
You are also given an integer d, representing the number of available dashers.

Each dasher can work only for one restaurant, and must handle all orders assigned to them from that restaurant.

Your task is to find the minimum capacity k such that all orders can be handled by the dashers.

A dasher cannot pick orders from multiple restaurants.


Examples

Example 1

Input:  orders = [3, 6, 7, 11],  d = 8
Output: 4

Example 2

Input:  orders = [30, 11, 23, 4, 20],  d = 5
Output: 30

这道题是 DoorDash VO 里非常典型的 二分答案(Binary Search on Capacity)+ 贪心 的负载分配题。

题目本质很简单:

  • 每家餐厅有固定订单量
  • 每个 dasher 有最大工作量 k
  • 一家餐厅可以分给多个 dasher,但一个 dasher 不能跨餐厅
  • 问:最小的 k 是多少?

关键点在于:

✅ 如何判断某个 k 是否可行?

对于每个餐厅 orders[i]:

 需要的 dashers = ceil(orders[i] / k)

把所有餐厅的需要加起来,只要 <= d,说明这个 k 可行。

✅ 为什么要用二分?

因为:

  • 能满足的 k(越大越容易满足)→ 单调性
  • 不能满足的 k(越小越不容易满足)→ 单调性

这种“满足 / 不满足”的分界点最适合用 binary search 找。

✅ 面试官会听什么?

  • 能不能准确表达出“capacity k 与 dashers 数量的关系”
  • 是否能正确写出 feasibility check
  • 是否想到二分,而不是从 1 一路试上去
  • 是否能清楚分析 time complexity

这道题其实难度不算高,但非常能体现候选人是否熟悉“二分答案”的思想。

VOprep 团队长期陪同学员实战各类大厂 OA 与 VO,包括 Doordash、Google、Amazon、Citadel、SIG 等,提供实时答案助攻、远程陪练与面试节奏提醒,帮助大家在关键时刻不卡壳。
如果你也在准备 Tiktok 或类似工程向公司,可以了解一下我们的定制助攻方案——从编程面到系统设计,全程护航上岸。

正文完
 0