1
# Runtime: 78 ms (Top 92.98%) | Memory: 14.2 MB (Top 33.69%)4
# n=len of logs, d=depth of stack5
def exclusiveTime(self, n: int, logs: List[str]) -> List[int]:6
# init result array to zeroes of length n (function ids)12
# function_id: start|end: timestamp14
# type cast function id and timestamp to int type16
timestamp = int(log[2])18
# detect start of a function call19
# stack[function_id, start_timestamp]23
# get the time taken by last function so far24
res[stack[-1][0]] += timestamp - stack[-1][1]25
# append the current function_id and start timestamp to the stack26
stack.append([id, timestamp])28
# get the time consumed by current function29
# dont forget to add 1 as the last unit of time should be included30
res[id] += timestamp - stack.pop()[1] + 132
# update the start time of last function in stack to get the cumulative result33
stack[-1][1] = timestamp + 1