Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Code Review: Log Parser for Time Spent
00:00
5 left

Code Review: Log Parser for Time Spent

HardPython

Problem

Code review: review a log parser that calculates time spent in a function.

Asked in the code review stage. Listed as an example from the code review question bank.

Task

Implement exclusive_time(n, logs). Each log has the form "function_id:start:timestamp" or "function_id:end:timestamp". Logs are properly nested. For every function ID, return the sum of inclusive durations, where an invocation ending at end after starting at start contributes end - start + 1 time units. Return a list of length n, ordered by function ID.

Constraints

  • 1 <= n <= 100
  • 1 <= logs.length <= 10^4
  • 0 <= function_id < n
  • Timestamps are nonnegative integers
  • Logs form valid, properly nested start and end pairs

Function Signature

def exclusive_time(n, logs):
Interviewer

Your question is Code Review: Log Parser for Time Spent. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.