title: String Reduction - Programming Contest . Solution needed
body: <p>I have a question which asks us to reduce the string as follows.</p>
  
  <blockquote>
    <p>The input is a string having only <code>A</code>, <code>B</code> or <code>C</code>. Output must be length of
    the reduced string</p>
    
    <p>The string can be reduced by the following rules </p>
    
    <p>If any 2 different letters are adjacent, these two letters can be
    replaced by the third letter.</p>
    
    <p>Eg  <code>ABA</code> -> <code>CA</code> -> <code>B</code> . So final answer is 1 (length of reduced string)</p>
    
    <p>Eg <code>ABCCCCCCC</code></p>
    
    <p>This doesn't become <code>CCCCCCCC</code>, as it can be reduced alternatively by</p>
    
    <p><code>ABCCCCCCC</code>-><code>AACCCCCC</code>-><code>ABCCCCC</code>-><code>AACCCC</code>-><code>ABCCC</code>-><code>AACC</code>-><code>ABC</code>-><code>AA</code> </p>
    
    <p>as here length  is 2 &lt; (length of <code>CCCCCCCC</code>)</p>
  </blockquote>
  
  <p>How do you go about this problem? </p>
  
  <p>Thanks a lot!</p>
  
  <p>To make things clear: the question states it wants the minimum length of the reduced string. So in the second example above there are 2 solutions possible, one <code>CCCCCCCC</code> and the other <code>AA</code>. So 2 is the answer as length of <code>AA</code> is 2 which is smaller than the length of <code>CCCCCCCC</code> = 8.</p>