title: Removing duplicate character from array
body: <p>While reading one book named <code>Cracking the coding interview</code> by <code>Gayle Laakmann</code>, i came across this question</p>
  
  <blockquote>
    <p>Design an algorithm and write code to remove the duplicate characters
    in a string without using any additional buffer. NOTE: One or two
    additional variables are fine. An extra copy of the array is not.</p>
  </blockquote>
  
  <p>and this code :-</p>
  
  <pre><code> public static void removeDuplicates(char[] str) {
          if (str == null) {
              return;
          }
          int len = str.length;
          if (len &lt; 2) {
              return;
          }
  
          int tail = 1;
  
          for (int i = 1; i &lt; len; ++i) {
              int j;
              for (j = 0; j &lt; tail; ++j) {
                  if (str[i] == str[j]) {
                      break;
                  }
              }
              if (j == tail) {
                  str[tail] = str[i];
                  ++tail;
              }
          }
          str[tail] = 0;
      }
  </code></pre>
  
  <p>which is supposed to remove duplicate character from the array. I don't quiet seem to understand what the algorithm is doing by replacing the same character again and again. I thought it's only me who feels that the algorithm is not working but infact when i ran this code it's giving me wrong outputs. Is this serious error in book or have i not understood the question?</p>