Company: Amazon_1march
Difficulty: medium
A fulfillment warehouse has n orders queued for processing, each carrying a priority value stored in an array priorities , where priorities[i] is the priority of the i th order. Processing runs backward, starting at the last order (index n - 1 ) and finishing at the first order (index 0). An order counts as "delayed" whenever some order with a lower priority gets processed ahead of it. The delay clock for an order starts the moment the first such lower-priority order begins processing, and stops once the order itself is processed. Assuming each order takes exactly 1 unit of time to process, work out the delay time for every order. Example: n = 4, priorities = [8, 2, 5, 3] Processing runs backward, from the last order to the first: Order 3 (priority 3): No prior orders processed, so delay = 0. Order 2 (priority 5): First lower-priority order processed before it is Order 3 (priority 3), so the delay for order 2 is the difference in their positions (since each order takes 1 unit of time t