You are given a sequence of n trees. The height of the i-th tree is h[i]. Each tree could be of one of k different colors. You are allowed to do ONE recoloring operation, in which you can recolor ALL trees with color C1, to color C2. Your objective is to MAXIMIZE the total height of contiguous block of trees of one color. Present an algorithm for this problem, and present its time complexity.
For example, suppose your trees are:
Tree T1, Height 17, Color: R (Red)
Tree T2, Height 20, Color: Y (Yellow)
Tree T3, Height 1, Color: G (Green)
Tree T4, Height 5, Color: G (Green)
Tree T5, Height 6, Color: Y (Yellow)
In this case, if you color YàG (or GàY), then the maximum height of G trees is 32. However, if you recolor YàR (or RàY), then the maximum contiguous height becomes 37, and is therefore the correct answer.