Get Function Execution Time
When multiple tasks are included in a single thread/CPU, the tasks are scheduled based on the principle of preemption. When a higher priority task arrives, the currently executing task with lower priority gets preempted, i.e., it becomes idle until the higher priority task is complete.
There are 3 functions to be executed in a single thread with IDs between 0 and n-1. Given an integer n representing the number of functions to be executed, and an array logs containing the timestamp and function ID, determine the exclusive time of each of the functions. It is noted that the total of execution time should be divided among functions according to their representing an integer log in the form {function_id, "start"|"end", timestamp} indicating when a function started or ended at a time identified by the timestamp value.
Note: While calculating the execution time of a function both the starting and ending times of the function calls are to be included. The log of the function calls is sorted by timestamp. When a function is preempted at the beginning of timestamp second, the log of this time stamp is {"preempting_id", "start", timestamp}. When a function function_id is preempted after completing timestamp second, the log record is {"after_timestamp_record"}.
Complete the function getFunctionExecutionTime in the editor.
getFunctionExecutionTime has the following parameters:
- 1.
int n: the number of functions to be executed - 2.
String logs[m]: the execution logs of the different calls to the functions
Returns
int[n]: the execution time of all functions with IDs [0,n-1]
💐, Aura Man with the hard carry!༊·°🌺𓍼ོ
n = 3 logs = ["0:start:0", "2:start:4", "2:end:5", "1:start:7", "1:end:10", "0:end:11"] return = [6, 4, 2]

- 1 ≤ n ≤ 100
- 1 ≤ m ≤ 500
- 0 ≤ function_id < n
- 0 ≤ timestamp ≤ 3*10^3
- The timestamps are given in non-decreasing order.
- No two starting timestamps and no two ending timestamps are equal
- Every function "start" call has a corresponding "end" call
- Count House Segments After DestructionOA · Seen May 2026
- Count Numbers with Even Number of DigitsOA · Seen May 2026
- Laser Robot Safe PathOA · Seen May 2026
- Longest Same-Character SubstringOA · Seen May 2026
- Cyclic Shift to Strictly Descending ArrayOA · Seen May 2026
- Dynamic Wall Building and Range QueryOA · Seen May 2026
- Queue Check-in Simulation with Capacity LimitOA · Seen May 2026
- Sum Digits Until OneSeen Dec 2024
public int[] getFunctionExecutionTime(int n, String[] logs) {
// write your code here
}