Company: Amazon_4th june_on campus _iit guwahti
Difficulty: medium
There are n processes to be executed on a CPU, and an array named priorities. Each process has a priority, priorities[i]. The CPU executes these processes one by one in reverse order, from the (n-1)th index to the 0th 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: n = 4 priorities = [8, 2, 5, 3] Start processing at the last index. process 3 = 3: No processes happened before, so it is not starved, i.e., starvation[3] = 0. process 2 = 5: The earliest process with a lower priority is process 3, hence starvation[2] = 3 - 2 = 1. process 1 = 2: No earlier process had lower priority, so starvation[1] = 0. process 0 = 8: The earliest process with a lower priority is process 3, hence starvatio