FastPrepExclusive Time of Functions
Problems/Exclusive Time of Functions

Exclusive Time of Functions

Microsoft logoMicrosoft● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The round is not named in the review. The author had a pair of DSA-focused interviews in one day for a Microsoft software engineering internship. A review names a well-known problem, Exclusive Time of Functions, with no input or rules.

Here the logs use the usual id:start:t and id:end:t format for one CPU. Calls are nested and in time order. A call ending at t also owns unit t, and idle units count for no function. You return each function's exclusive time. There are 1 to 100 functions, 2 to 500 logs and timestamps up to 10^9.

Our version is about 95% the same as the reported question.

A single-threaded CPU runs n functions with ids 0 to n - 1. Functions can call other functions, and themselves. Time is split into whole units numbered 0, 1, 2, ....

  • "id:start:t" means a call of function id begins at the start of unit t. The call that was running is paused.
  • "id:end:t" means that call finishes at the end of unit t, so unit t still belongs to it. The paused caller, if any, then resumes.

The exclusive time of a function is the number of units in which one of its calls is the one actually running. Units when nothing runs belong to no function.

Return an array whose i-th value is the exclusive time of function i.

Function

exclusiveTime(n: int, logs: List<String>) → int[]

Examples

Example 1

n = 2logs = ["0:start:0","1:start:3","1:end:4","0:end:7"]return = [6,2]

Function 0 runs during time units 0, 1 and 2. Function 1 then runs during units 3 and 4. Function 0 continues during units 5, 6 and 7. So function 0 gets 3 + 3 = 6 units and function 1 gets 2.

Example 2

n = 1logs = ["0:start:0","0:start:2","0:end:3","0:end:5"]return = [6]

Function 0 calls itself. The outer call runs during units 0 and 1, the inner call during 2 and 3, and the outer call again during 4 and 5. All six units belong to function 0, so the answer is [6].

Example 3

n = 3logs = ["0:start:0","0:end:0","2:start:1","2:end:4"]return = [1,0,4]

Function 0 starts and ends in unit 0, so it gets 1 unit. Function 2 runs during units 1 to 4, which is 4 units. Function 1 never runs and gets 0.

Constraints

  • 1 <= n <= 100
  • 2 <= logs.length <= 500
  • Each log is "id:start:t" or "id:end:t" with 0 <= id < n and 0 <= t <= 10^9.
  • The logs are in time order and describe properly nested calls: every end closes the most recent call that is still open, every call is closed, a start comes later than every earlier log, and no two end logs share a timestamp.

More Microsoft Onsite Interview questions

  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
  • Totals from a Tiered Rate TableONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Flatten a Mixed JSON ListNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
  • Fountain SafetyGoogle · ONSITE INTERVIEWGoogle interview questions
  • Trace Events from Stable Whole-Stack StatesAnthropic · ONSITE INTERVIEWAnthropic interview questions
  • Evaluate Ordered Action RulesStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Surviving Balls after Directional CollisionsSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Render a Comment HierarchyAmazon · ONSITE INTERVIEW
  • Asteroid CollisionAdobe · ONSITE INTERVIEWAdobe interview questions
  • Most Frequent Call Path in Interleaved LogsRoblox · ONSITE INTERVIEWRoblox interview questions

Interview reports that mention this question

  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int[] exclusiveTime(int n, List<String> logs) {
        // Write your code here.
    }
}
Checking account…