Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Note that if the number is negative it's the same as positive but you look for the minimum instead.
In the case of maximum, if s[i] < x it's optimal that x is put before s[i].
In the case of minimum, if s[i] > x it's optimal that x is put before s[i].