# LC5489 Exclusive Time of Functions **Approach.** Stack of running ids; charge elapsed time to the top on each event. ```python def exclusiveTime(n, logs): res, st, prev = [0]*n, [], 0 for l in logs: i, t, ts = l.split(':'); i, ts = int(i), int(ts) if t == 'start': if st: res[st[-1]] += ts - prev st.append(i); prev = ts else: res[st.pop()] += ts - prev + 1; prev = ts + 1 return res ``` **Interview tip.** Name the pattern first, then the invariant, then code. To rehearse explaining solutions under pressure, try [undetectable AI interview copilot](https://www.linkjob.ai/) — https://www.linkjob.ai/ .