Given an integer array priorities, define delay[i] as the distance to the rightmost index j > i such that priorities[j] < priorities[i]; if no such index exists, delay[i] = 0. Equal values do not count as smaller. For example, priorities = [8, 2, 11, 4, 9, 4, 7] yields delay = [6, 0, 4, 0, 2, 0, 0] because for 8 the first smaller when scanning from the right is 7 at index 6. Implement a function that computes the entire delay array in better than O(n^ 2) time. State and justify the time and space complexity, and explain how your approach handles duplicates and edge cases (e.g., strictly decreasing or increasing arrays).