Answered step by step
Verified Expert Solution
Question
1 Approved Answer
[ 5 : 0 9 PM , 1 2 / 2 7 / 2 0 2 3 ] Janarthanan Uniq: When multiple tasks are executed
: PM Janarthanan Uniq: When multiple tasks are executed on a singlethreaded CPU, the tasks are scheduled based on the principle of preemption. When a higherpriority task arrives in the execution queue, then the lowerpriority task is preempted, ie its execution is paused until the higherpriority task is complete.
There are n functions to be executed on a singlethreaded CPU, with each function having a unique ID between and n Given an integer n representing the number of functions to be executed, and an execution log as an array of strings, logs of size m determine the exclusive times of each of the functions. Exclusive time is the sum of execution times for all calls to a function. Any string representing an execution log is of the form functionid : prime
: PM Janarthanan Uniq: Example
Suppose n logs prime prime s tart : prime prime :start::end::start::end: e nd
Timestamp
Function Running
Remarks
Function starts
Function starts and Function is preempted
Function ends
Function O resumes
Function starts and Function is preempted
Function ends
Function O ends
: PM Janarthanan Uniq: Thus the total number of seconds allocated to functions and are and respectively. Hence the answer is
Function Description
Complete the function getTotal ExecutionTime in the editor below.
getTotalExecutionTime has the following parameters:
int n: the number of functions to be executed
string logsm: the execution logs of the different calls to the functions
Returns
integrate n dn the execution time of all functions with IDs from n
Constraints
n
m
function id logs IntStream.range logsCountmapToobj i f
try
return bufferedReader.readLine;
catch IOException ex
throw new RuntimeExceptionex;
collecttoList;
result Result getTotal ExecutionTimen logs:
: PM Janarthanan Uniq: bufferedWriter.write
result.stream
mapObject::toString
collectjoining
;
bufferedReader.close; bufferedWriter.close;
: PM Janarthanan Uniq: class Result
public static List getTotal ExecutionTimeint n List
logs
Write your code here
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started