Task delay times from the farthest smaller priority
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.
No answer yet. Write the first one; the best answer gets endorsed.
