title: Divide and Conquer Algorithm [char array]
body: <p>Let w be an array of length n. Write a divide and conquer algorithm in java to determine the number of times 3 consecutive identical caracters appear. Below is the algorithm I've written.  The answer should be 5 but it gives me a 0. Can anyone spot the error?
  Given w = abrabbbcccccfhdddgfr the algorithm should return 5 because it meets five occurrences of 3 consecutive identical characters : 1 time bbb, 3 times ccc e 1 time ddd</p>
  
  <pre><code>public class Test {
  
      public static void main (String[] args){
          char[] w =     {'a','b','r','a','b','b','b','c','c','c','c',
                  'c','f','h','d','d','d','g','f','r'};
          System.out.println(conta_triple_main(w));
      }
  
      public static int conta_triple_main(char[] w){
          if (w.length &lt;= 2)
              return 0;
          else
              return conta_triple(w, 0, w.length-1);
      }
  
      public static int conta_triple(char[] w, int i, int f){
          int m,result;
          if( i &gt;= f-1)
              return 0;
          else {
              m = (i + f)/2;
              int sx = conta_triple(w, i, m);
              int dx = conta_triple(w, m+1, f);
              result = sx + dx;
              if ((m &gt;= w.length-1) &amp;&amp; (w[m-1] == w[m]) &amp;&amp; (w[m] == w[m+1]))
                  result++;
              if ((m &gt;= w.length-2) &amp;&amp; (w[m] == w[m+1]) &amp;&amp; (w[m+1] == w[m+2]))
                  result++;
          }
          return result;
      }
  }
  </code></pre>