I have an exercise that needs to be done with O(n) time complexity, however, I can only solve it with an O(n^2) solution.
You have an array and you need to count the
You apply dynamic programming. For every position you compute 3 values:
So given this value for position i you can easily compute the new ones for position i+1.