Sponsored
Use these hints if you're stuck. Try solving on your own first.
Go through each element and test the optimal replacements.
There are only 2 possible replacements for each element (higher and lower) that are optimal.
Solve with full IDE support and test cases