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
The solution uses a stack to simulate function calls. A“begin”event pushes a new frame and pauses the previous function, while an“end”event pops the function and accumulates its exclusive time based on timestamp differences. Properly tracking the previous timestamp is essential to handle nesting correctly.
The VOprep team has long accompanied candidates through various major company OAs and VOs, including Meta, Amazon, Citadel, SIG, providing real-time voice assistance, remote practice, and interview pacing reminders to help you stay smooth during critical moments. If you are preparing for these companies, you can check out our customized support plans—from coding interviews to system design, we offer full guidance to help you succeed.