Self Time per Function
logs records a single-threaded program in time order. Each entry is "NAME start T" or "NAME end T", where T is a moment in time. A call runs from its start to its end, but it is paused while a call that started inside it is running. Calls are properly nested: each end closes the most recent call that has not ended, which has the same name. A function may call itself.
The self time of a call is the time it was running and not paused, so a call from moment 2 to moment 5 with nothing inside it has self time 3. Return a dictionary mapping each function name to the total self time of all its calls (an empty dictionary when logs is empty).
Example 1
main runs from 0 to 2 and from 5 to 9, which is 6, and load runs from 2 to 5.
Example 2
Between them, the two calls of f run from 0 to 1, 1 to 3, 3 to 4 and 4 to 6, which is 6. The call of g takes no time.
Constraints
0 <= len(logs) <= 100- names are 1 to 8 lowercase letters
- times are whole numbers from
0to1000and never decrease - the logs are well formed and every call ends
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.