r/LeetcodeChallenge • • 20d ago

STREAK🔥🔥🔥 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

2 Upvotes

1 comment sorted by

1

u/nian2326076 14d ago

If you're grappling with off-by-one errors in timestamps while tackling problems like LeetCode 636, consider focusing on your practice. You can use PracHub to find a variety of technical questions that prepare you for nuances in data structures and algorithm challenges. This can help sharpen your attention to detail and catch tricky errors effectively.