← Questions

Task delay times from the farthest smaller priority

0
AmazonCodingLast asked Sep 2025

Task priorities are given in an array and processed from right to left. A task's delay time is the distance from it to the farthest task on its right that has a smaller priority, or 0 if none does. For [8, 2, 11, 4, 9, 4, 7] the answer is [6, 0, 4, 0, 2, 0, 0]. The O(n^2) scan times out; find an O(n log n) solution.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding