Assuming string as only lower case characters.
now declare two unsigned int as x,y and ar[26].
now when u encounter any character c among (a,...z) first time u will set
(c-'a') bit of x and check if it has already been occurred then set (c-'a')
bit of y.and ar[i] will be storing the very first occurrence of the c
character where i will be (c-'a').
now traverse the array and output will be (i+'a') where a[i] is min and
(ith) bit in x is set and ith bit in y bit is unset.

On Mon, Jul 18, 2011 at 7:26 PM, vaibhav shukla <vaibhav200...@gmail.com>wrote:

> one solution could be:
>
> #include<stdio.h>
> #include<string.h>
> char non_repetition(char *p,int size)
> {
>     int i,j,flag=0;
>     for(i=0;i<size;i++)
>     {
>         for(j=0;j<size;j++)
>         {
>             if(j==i)
>                 continue;
>             if(p[i]==p[j])
>                 flag=1;
>         }
>         if(flag==0)
>             return p[i];
>         else
>             flag=0;
>     }
>     return '\0';
> }
>
> int main()
> {
>     char
> str[]="aaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccc
> *V*cccccccccccccccccccccccc";
>     int len=strlen(str);
>     char firstNR=non_repetition(str,len);
>     if(firstNR=='\0')
>         printf("all are repeating at least once\n");
>     else
>         printf("first non repeated character is=%c\n",firstNR);
>     return 0;
> }
>
> gives *V* as the output
>
> On Mon, Jul 18, 2011 at 6:45 PM, Dumanshu <duman...@gmail.com> wrote:
>
>> You are given a long string and you have to print the "first" non
>> repeating character.
>> Solve it keeping SC and TC in mind. That is present both solutions,
>> one with high SC and low TC and viceversa.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>
>
> --
>   best wishes!!
>     Vaibhav
>     DU-MCA
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Varun Pahwa
B.Tech (IT)
7th Sem.
Indian Institute of Information Technology Allahabad.
Ph : 09793899112
Official Email :: rit2008...@iiita.ac.in
Another Email :: varunpahwa.ii...@gmail.com

People who fail to plan are those who plan to fail.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to