title: Implement an algorithm to determine if a string has all unique characters using bit twiddling
body: <p>How would I <strong>best</strong> implement a Java function which accepts a String parameter and returns <code>true</code> or <code>false</code> depending on whether the String is comprised of all different characters or not.</p>
  
  <p>This is an interview question. The implementation should use bit masking to store the occurrence of characters and no other auxiliary data structures.</p>
  
  <p>Note: the requirement to use bit masking makes this question different from:</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/3869526/how-to-determine-if-all-characters-in-a-string-are-equal">How to determine if all characters in a string are equal</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/4987863/determine-if-a-string-has-all-unique-characters">determine if a string has all unique characters?</a></p></li>
  </ul>
  
  <p>As requested, here's my effort so far. Please re-open the question if possible now:</p>
  
  <pre><code>public static boolean hasAllUniqueCharactersUsingBitMasking(String string) {
    final int length = string.length();
    final int nBitsToStoreAllUnicodeCharacters =
        (int) Math.ceil(Math.log(Character.MAX_CODE_POINT) / Math.log(2d));
    BitSet bitSet = new BitSet(nBitsToStoreAllUnicodeCharacters);
    for (int i = 0; i &lt; length; i++) {
      char c = string.charAt(i);
      if (bitSet.get(c)) {
        return false;
      }
      bitSet.set(c);
    }
    return true;
  }
  </code></pre>