Sponsored
Use these hints if you're stuck. Try solving on your own first.
Use suffix/prefix arrays.
prefix[i] records the maximum value in range (0, i - 1) inclusive.
suffix[i] records the minimum value in range (i + 1, n - 1) inclusive.
Solve with full IDE support and test cases