Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
The trivial solution is to check the time days before and after each day. There are a lot of repeated operations using this solution. How could we optimize this solution?
We can use precomputation to make the solution faster.
Use an array to store the number of days before the i<sup>th</sup> day that is non-increasing, and another array to store the number of days after the i<sup>th</sup> day that is non-decreasing.