my question is that given a list of integers (lets say A), for each element A[i], find the smallest element A[j] which could satisfy A[i] < A[j] and i < j. Return -1 if there is no such element.
For example, given [4,2,1,9,3], return [9,3,3,-1,-1]
I have come up with a brute force solution which costs $O(n^2)$, but I'm wondering if there could be a more efficient solution.