Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Calculate the largest <code>x</code> such that <code>nums[0..x]</code> is strictly increasing.
Calculate the smallest <code>y</code> such that <code>nums[y..nums.length-1]</code> is strictly increasing.
For each <code>i</code> in <code>[0, x]</code>, select the smallest <code>j</code> in <code>[y, nums.length - 1]</code>. Then we can keep the prefix with any suffix of <code>[j, nums.length - 1]</code> (including the empty one).
Note that when <code>i</code> increases, <code>j</code> won’t decrease. Use two-pointers.
Note that we cannot delete an empty array, but we can delete the whole array.