Implement an algorithm to determine if a string has all unique characters
If I'd asked an interview question, and got this as an answer (at least as the first answer) I think my immediate reaction would be to consider it excessively clever.

To make much sense, along with the conditions you gave, I'd have had to specify that minimizing memory usage was absolutely crucial.

Under ordinary circumstances, I'd expect an answer something like this:

bool all_unique(std::string const &amp;input) { 
    std::map&lt;char&gt; temp(input.begin(), input.end());
    return temp.size == input.size();
}


...or something like this:

bool all_unique(std::string input) { 
    std::sort(input.begin(), input.end());
    auto p = std::unique(input.begin(), input.end());
    return p == input.end();
}


There are, of course, variations on these themes (e.g., perfectly reasonable and acceptable to use unordered_set instead of set).

Either of these will work with a much wider range of inputs than you've specified. They will use more storage, but the amount they use is still too small to matter under any normal circumstances.

If somebody were going to craft a special-purpose set of their own, I'd normally expect them to start from std::bitset or std::vector&lt;bool&gt;. I guess if they insisted on starting with a native type to represent their bits, I wouldn't object too terribly much, but I'd be a little disappointed if they chose int for that type.


If you want a bag of bits, you should usually use an unsigned type.
If you want at least 32 bits, you should use a type that guarantees at least 32 bits (int only guarantees at least 16 bits).


As such, obvious choices would be unsigned long and uint32_t.