top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to find the first non-repeated character in a string of n length?

+3 votes
349 views
How to find the first non-repeated character in a string of n length?
posted Mar 9, 2014 by Atul Mishra

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

If you have plenty of memory then try the following code in C (may not be the best way)

unsigned char find_first_non_repeat(unsigned char *string)
{
    int chars[256];
    int i=0;
    memset(chars, 0, sizeof(chars));

    while (string[i++])
        chars[string[i]]++;

    i = 0;
    while (string[i++])
        if (chars[string[i]] == 1) return string[i];

    return 0xFF; // 0xff means no non-repeat character
}
answer Mar 9, 2014 by Salil Agrawal
Similar Questions
+6 votes

For example: It returns ‘b’ when the input is “abaccdeff”.

0 votes

Find the first non repeating character in a string.

For example
Input string: "abcdeabc"
Output: "e"

0 votes

Given a string S and set of strings U. Find the length of longest prefix of S that can be formed using strings in U.

For example you have following -

S= “absolute”
U={“abs”,”xyz”,”ol”,”te”}

Answer: 5 i.e "absol"

Now the task is to have the algorithm/program for the above problem, please help me with this?

...