</>EmbeddedInterview

Find the first non-repeated character in a string.

Easy"Coding: Memory & String Functions"
int first_unique_char(const char *s)
{
    int count[256] = {0};
    for (const unsigned char *p = (const unsigned char *)s; *p; p++) count[*p]++;
    for (const unsigned char *p = (const unsigned char *)s; *p; p++)
        if (count[*p] == 1) return *p;
    return -1;                                         /* none */
}
/* "swiss" -> 'w' */

Points: two passes: count, then scan in original order; O(n) time, O(1) space (fixed 256-entry table).