Sponsored
Use these hints if you're stuck. Try solving on your own first.
Use Dynamic programming. Keep the highest value and lowest value you can achieve up to a point.
Solve with full IDE support and test cases