Several processes are scheduled for execution on an AWS server.
On one server, n processes are schedule where the ith process is assigned
a priority of priority[i]. The processes are placed sequentially in a queue
and are numbered 1, 2,..,n. The server schedules the processes per the following algorithm:
p. (if there is no such priority or p = 0, the algorithm is terminated)p, call them process1 and process2.process1 and removes it from the queue.process2 to floor(p/2).Given the initial priority of the processes, find the final priority of the processes which remain after the algorithm terminates.
Note that relative the arrangement of remaining processes in the queue remains the same,only their priorities change.
Complete the function getPrioritiesAfterExecution in the editor.
getPrioritiesAfterExecution has the following parameter:
-
int priority[n]:the initial prorities of processes
Returns
-
int[]:the final priorities of the remaining processes
priority = [6, 6, 6, 1, 2, 2] return = [3, 6, 0]

priority = [4, 4, 2, 1] return = [0]

priority = [2, 1, 5, 10, 10, 1] return = [0, 1]
p = 10 and process1 = 4, process2 = 5. So, update the priority = floor(10/2) = 5 of process2 and remove process1. Current set of process priorities, priority = [2, 1, 5, 5, 1].
p = 5 and process1 = 3, process2 = 4. So, update the priority = floor(5/2) = 2 of process2 and remove process1. Current set of process priorities, priority = [2, 1, 2, 1].
p = 2 and process1 = 1, process2 = 3. So, update the priority = floor(2/2) = 1 of process2 and remove process1. Current set of process priorities, priority = [1, 1, 1].
p = 1 and process1 = 1, process2 = 2. So, update the priority = floor(1/2) = 0 of process2 and remove process1. Current set of process priorities, priority = [0, 1].
1 ≤ n ≤ 10^51 ≤ priority[i] ≤ 10^9
- Closest Version DateONSITE INTERVIEW · Seen Jul 2026
- Maximum Concurrent Processes (Bar Raiser Round)ONSITE INTERVIEW · Seen Jul 2026
- Maximum Product New RatingOA · Seen Jul 2026
- Permutation SorterOA · Seen Jul 2026
- Get Distinct Pairs (Also apply to AS intern)Seen Jul 2026
- Maximum Final ValueSeen Jul 2026
- Minimum Delivery Center InconvenienceOA · Seen Jun 2026
- Unfulfilled Customers by Inventory PriorityOA · Seen Jun 2026
public int[] getPrioritiesAfterExecution(int[] priority) {
// write your code here
}