Meta 高频面试题:根据日志计算每个函数的独占运行时间

69次阅读
没有评论
We are profiling the performance of some app. 
App logs an event for beginning and end of each function.
An event has three fields: function name, timestamp, and type (begin or end).

Example:
foo, 10, b
bar, 20, b
bar, 50, e
foo, 100, e

Expected output:
foo: 60
bar: 30

整题是典型的调用栈模拟问题。当遇到 begin 时,将当前函数压栈并暂停上一个函数的计时;当遇到 end 时,弹栈并根据时间差累积当前函数的独占时间。需要记录上一条日志的时间戳,避免重复计算,并精确处理函数嵌套与覆盖关系。

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

正文完
 0