Google 面试题 #10 — 电梯乘客载荷与目的地解析 – 谷歌面经 – 一亩三分地 – 面试辅助 – VO help

8次阅读
没有评论

You are given a 2-D grid representing two elevators (left elevator A, right elevator B).
Each cell may contain a digit representing the number of people waiting on that floor for that elevator.

Example grid:

[A] [B]

|1 2 3|
|4 5 6|
|7 8 #|
[C] [D]

Legend:

  • Column A = left elevator
  • Column B = right elevator
  • Numbers = number of people waiting
  • # = no service / broken panel
  • Floors go from bottom to top

You are also given a query describing a request:

7#3   → going to the 7th floor with 3 people

Task

Given the grid and a request in the format:

<target-floor>#<people-count>

Write a function that determines:

  1. Which elevator (A or B) should serve the request
  2. Whether that elevator has enough capacity
  3. Return the total number of people currently waiting along the path to the target floor

You may assume:

  • Floor numbers correspond to rows in the grid
  • Elevators serve straight vertical paths
  • If a floor contains #, that elevator cannot serve that floor
  • If both elevators can serve the floor, choose the one with fewer total waiting people

你有一个电梯面板矩阵,每一列对应一个电梯(左 A,右 B)。数字表示该电梯在对应楼层等待的人数;# 表示该楼层无法服务。

输入查询形如:

7#3   表示 3 个人想去 7 楼

需要做:

  1. 判断电梯 A、B 哪一个可以服务到 7 楼(如果遇到 # 则不能服务)。
  2. 统计从底部到 7 楼沿途所有楼层的等待人数总和。
  3. 若两个电梯都能服务,则选择等待人数更少的电梯。

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

正文完
 1