You have an array of integers.
In one step, you can change the value at any index into any integer value. What is the minimum number of steps in which you can make the array non-decreasing?
Eg 1:
If the array is [8, 12, 11, 15],
We can change the value at the index 2 from 11 to 13. Then the array becomes [8, 12, 13, 15]
So, no of steps needed = 1
Eg 2:
If the array is [9, 2, 5, 18, 20, 25, 19],
We can change the value at the index 0 from 9 to 2 and the value at the index 6 from 19 to 30. Then the array becomes [2, 2, 5, 18, 20, 25, 30]
So, no of steps needed = 2
Eg 3:
If the array is [9, 11, 5, 7],
We can change the value at the index 2 from 5 to 11 and the value at the index 3 from 7 to 11. Then the array becomes [9, 11, 11, 11]
So, no of steps needed = 2
Eg 4:
If the array is [13, 12, 10, 7, 6],
After making the changes, the array becomes [13, 13, 13, 13, 13] or [6, 7, 10, 12, 13]. There are multiple ways of doing this.
So, no of steps needed = 4
One way I tried would be to find all the decreasing subsequences and add the length of them - 1 to a variable named ans. Then return it. But it's failing in the Eg 3 mentioned above.
How to solve this?