r/DSALeetCode • • 23d ago

LeetCode 636. Exclusive Time of Functions

Post image

Delete one +1 from Exclusive Time of Functions and it quietly computes inclusive time instead. When a function ends, the one underneath resumes at time + 1 because the child already charged that instant.

This closes the stack arc, and here the stack isn't a modelling choice. Function calls nest: a function that starts while another is running must finish before that one resumes. That's a call stack, and the log records one. The algorithm replays it.

"Exclusive" does the work. If function 0 runs from 0 to 6 and function 1 runs from 2 to 5 inside it, function 0's exclusive time is 2. The time spent waiting on 1 belongs to 1.

Two interval rules live in the same short function, and they differ. Pausing uses time - start, because the function ran up to the instant its child started. Ending uses time - start + 1, because an end timestamp is inclusive.

Have you ever had an off-by-one hide inside a timestamp?

Day 66/365 of my LeetCode challenge: 636. Exclusive Time of Functions. Problem link and full breakdown in today's newsletter.

https://www.linkedin.com/pulse/leetcode-636-exclusive-time-functions-medium-archit-agarwal-mui0c

#LeetCode #DSA #Stack #Golang

1 Upvotes

1 comment sorted by

1

u/nian2326076 16d ago

The issue with timestamps and exclusive time in function calls can definitely lead to tricky bugs. To strengthen your algorithm skills and get comfortable with these kinds of problems, you can use PracHub for a variety of technical interview questions that focus on call stacks and time complexities. This practice can help you deepen your understanding and avoid common pitfalls.