Problem with sample-input_and_output provided

In sample-input, time starts at 0 and ends at 6, that is total time consumed is (6-0) = 6

But in sample-output, the total time consumed turns out to be (3 + 4) = 7

From where this additinal 1 comes ?

Hello @maheshghamand could you please elaborate which question or content you are talking about?

Sample input provided in question is -

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

Sample output provided is -

3 4

Here, the operation time of function-with-id-1, starts at 2 (1:start:2) and ends at 5 (1:end:5) means total time consumed should be - 5-2 = 3, but instead of 3, they provided answer for time consumption of function-with-id1 as 4

The way to solve this problem is to create a gantt chart first. If you have already studied about Gantt charts in Operating systems, this is a straightforward question.

However if not, the approach is to take an auxiliary array of size N, where arr[i-1] denotes the time spent by function i in the singlethreaded CPU.
Next sort the logs according to the timestamp. This will provide a serial order to your functions as your CPU is single threaded.
Finally take an boolean variable that denotes whether the CPU is free or not. If it is free, straightaway start the next process. Else remove the process executing in cpu and update its execution time in the arr.

OK, thanks for the help !

@maheshghamand you can mark this as resolved.
Happy Learning!!

How to mark as - resolved ?

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

You didn’t told me how to mark this query as “resolved”, I couldn’t find any button here which I could click to resolve this query/question.