Company: IBM___.
Difficulty: medium
Process Starvation Time Description There are n processes to be executed on a CPU, and an array named priorities . Each process i has a priority, priorities[i] . The CPU executes these processes one by one in reverse order, from the ( n-1 ) th index to the 0 th index. A process experiences starvation if a lower-priority process is executed before it. A process's starvation period begins when the earliest lower-priority process starts executing and ends when the process itself is finally executed. Given that each process takes 1 unit of time to execute, calculate the starvation time for each process. Example Input: n = 4 priorities = [8, 2, 5, 3] Output: [3, 0, 1, 0] Explanation: The processes are executed in the order of their indices: 3, 2, 1, 0. Process 3 (priority 3): No processes were executed before it, so it is not starved. starvation[3] = 0 . Process 2 (priority 5): The earliest process executed before it with a lower priority is process 3 (priority 3). Hence, starvation[2] = 3