string reduction in csharp

Code Example - string reduction in csharp

                
                        Input: str = "aaabccddd"
Output: 3
Following are sequence of operations:
aaabccddd -> abccddd -> abddd -> abd

Input: str = "aa"
Output: 1