The goal is, given an array A of nonnegative numbers, create a new array B such that b[i] is the smallest of all numbers in A[i+1:] that are larger than A[i] and -1 if there are no such numbers.
For example:
A = [1,3,2,4,1] gives
B = [2,4,4,-1,-1]
Any help?