Exclusive CPU Time per Function From Single-Threaded Profiler Logs

Last updated: November 29, 2026

Quick Overview

A single-threaded profiler emits logs like "id:start:t" and "id:end:t", where an end at time t means the function ran through the end of unit t. Return each function's exclusive time, not counting time spent in functions it called.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


A single-threaded profiler emits logs like "id:start:t" and "id:end:t", where an end at time t means the function ran through the end of unit t. Return each function's exclusive time, not counting time spent in functions it called.

Profiling is a big deal for Meta's performance teams, and this question is a frequently seen Meta screen problem. The interviewer checks stack-based simulation and, above all, the off-by-one difference between start and end timestamps.

What the Interviewer Expects
  • Uses a stack of currently running function ids
  • Tracks the previous timestamp to attribute elapsed time
  • Handles the inclusive end timestamp (+1) correctly
  • Supports recursion, where a function calls itself
  • Processes logs in one pass
Key Topics to Cover
Stack
Simulation
Parsing
Intervals
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Logs come from multiple threads interleaved; what changes?
  • Also return inclusive time per function.
  • Logs may be malformed (end without start); how do you detect and report it?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Logs are sorted by time and well formed. Function ids are 0..n-1. A start at t begins at the start of unit t; an end at t finishes at the end of unit t. Return a list of n integers....

High-Level Design

Keep a stack of running ids and prev, the first time unit not yet attributed. On start t: if a function is running, it owns t - prev units; push the new id and set prev = t. On end t: the to...


Submit Your Answer
Markdown supported