{"id":"279eb369-e12c-4c27-bb9f-7cbf794461b0","name":"Exclusive Time Of Functions","description":"1: On a single-threaded CPU, we execute a program containing n functions. Each function has a unique ID between 0 and n-1.\r\n2: You are required to find the total execution time of each function.\r\n3: You are given len number of logs, where logs[i] represents the ith log message formatted as a string \"{function_id}:{\"start\" | \"end\"}:{timestamp}\", telling start or end time of function with id function_id.\r\n\r\nNote that a function can be called multiple times, possibly recursively.","inputFormat":"A number n representing number of functions.\r\nA number len representing count of logs.\r\nlog1\r\nlog2\r\n...len number of logs.","outputFormat":"print in different lines Exclusive Time Of Functions from id 0 to n-1.","constraints":"1: 1 &lt;= n &lt;= 100\r\n2: 0 &lt;= function_id &lt; n\r\n3: No two start events will happen at the same timestamp.\r\n4: No two end events will happen at the same timestamp.\r\n5: Each function has an start time and an end time.","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nint main(){\n //write your code here\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n // use read for taking input\r\n }\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"2\r\n4\r\n0:start:0\r\n1:start:2\r\n1:end:5\r\n0:end:6","sampleOutput":"3\r\n4\r\n","questionVideo":"https://www.youtube.com/embed/dsusgzffTDA","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8c6022a5-8654-4226-918f-8110af738bd4","name":"Stacks For Intermediate","slug":"stacks-for-intermediate-688","type":0},{"id":"a428e110-9f94-4b82-b2e3-e3c52de6da59","name":"Exclusive Time Of Functions","slug":"exclusive-time-of-functions","type":1}],"next":{"id":"05072123-8517-4277-9b0d-cdfb30be4ea1","name":"Exclusive Time Of Functions Medium MCQ","type":0,"slug":"exclusive-time-of-functions-medium-mcq"},"prev":{"id":"39ffbfe8-92a7-417f-a425-ced5f3e6bfa6","name":"Online Stock Span","type":3,"slug":"online-stock-span"}}}

Exclusive Time Of Functions

1: On a single-threaded CPU, we execute a program containing n functions. Each function has a unique ID between 0 and n-1. 2: You are required to find the total execution time of each function. 3: You are given len number of logs, where logs[i] represents the ith log message formatted as a string "{function_id}:{"start" | "end"}:{timestamp}", telling start or end time of function with id function_id. Note that a function can be called multiple times, possibly recursively.

{"id":"279eb369-e12c-4c27-bb9f-7cbf794461b0","name":"Exclusive Time Of Functions","description":"1: On a single-threaded CPU, we execute a program containing n functions. Each function has a unique ID between 0 and n-1.\r\n2: You are required to find the total execution time of each function.\r\n3: You are given len number of logs, where logs[i] represents the ith log message formatted as a string \"{function_id}:{\"start\" | \"end\"}:{timestamp}\", telling start or end time of function with id function_id.\r\n\r\nNote that a function can be called multiple times, possibly recursively.","inputFormat":"A number n representing number of functions.\r\nA number len representing count of logs.\r\nlog1\r\nlog2\r\n...len number of logs.","outputFormat":"print in different lines Exclusive Time Of Functions from id 0 to n-1.","constraints":"1: 1 &lt;= n &lt;= 100\r\n2: 0 &lt;= function_id &lt; n\r\n3: No two start events will happen at the same timestamp.\r\n4: No two end events will happen at the same timestamp.\r\n5: Each function has an start time and an end time.","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nint main(){\n //write your code here\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n // use read for taking input\r\n }\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"2\r\n4\r\n0:start:0\r\n1:start:2\r\n1:end:5\r\n0:end:6","sampleOutput":"3\r\n4\r\n","questionVideo":"https://www.youtube.com/embed/dsusgzffTDA","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8c6022a5-8654-4226-918f-8110af738bd4","name":"Stacks For Intermediate","slug":"stacks-for-intermediate-688","type":0},{"id":"a428e110-9f94-4b82-b2e3-e3c52de6da59","name":"Exclusive Time Of Functions","slug":"exclusive-time-of-functions","type":1}],"next":{"id":"05072123-8517-4277-9b0d-cdfb30be4ea1","name":"Exclusive Time Of Functions Medium MCQ","type":0,"slug":"exclusive-time-of-functions-medium-mcq"},"prev":{"id":"39ffbfe8-92a7-417f-a425-ced5f3e6bfa6","name":"Online Stock Span","type":3,"slug":"online-stock-span"}}}
plane

Editor


Loading...

Exclusive Time Of Functions

medium

1: On a single-threaded CPU, we execute a program containing n functions. Each function has a unique ID between 0 and n-1. 2: You are required to find the total execution time of each function. 3: You are given len number of logs, where logs[i] represents the ith log message formatted as a string "{function_id}:{"start" | "end"}:{timestamp}", telling start or end time of function with id function_id. Note that a function can be called multiple times, possibly recursively.

Constraints

1: 1 <= n <= 100 2: 0 <= function_id < n 3: No two start events will happen at the same timestamp. 4: No two end events will happen at the same timestamp. 5: Each function has an start time and an end time.

Format

Input

A number n representing number of functions. A number len representing count of logs. log1 log2 ...len number of logs.

Output

print in different lines Exclusive Time Of Functions from id 0 to n-1.

Example

Sample Input

2 4 0:start:0 1:start:2 1:end:5 0:end:6

Sample Output

3 4

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode