@Abhijit.  Does your code takes O(N^2)?  I think the following code
would do it in O(N)

iterate the string once:

void remove(char *a){
                if(!a){
                int i = 0, j = 1;
                while(a[j]!='\0'){
                        if(i<0 || a[i]!=a[j]){
                                if(j-1>i){
                                        a[i+1] = a[j];
                                }
                                i++;j++;
                        }else{
                                for(;a[j]==a[i];j++);
                                i--;
                        }
                }
                a[i+1] = '\0';
        }
}

On Feb 14, 11:17 pm, Tushar Bindal <[email protected]> wrote:
> if we have "RBGGGBGGBR"
> what should be the answer???
> "RBGR" or ""(empty string)
>
> On Mon, Feb 7, 2011 at 3:51 PM, rajan goswami 
> <[email protected]>wrote:
>
>
>
>
>
>
>
>
>
> > yeh.
> > Agree with ramkumar.
> > Simplest solution is to use Stack...
>
> > On Sun, Feb 6, 2011 at 8:11 PM, Abhijit K Rao 
> > <[email protected]>wrote:
>
> >> I could not get it for recursively, but iteratively, I coded a solution.
> >> If anyone knows recursively,
> >> let us know please.
>
> >> #include<stdio.h>
> >> void main()
> >> {
> >>      char s[18]="DGGDBCBHH";
> >>      int i=0,j=0;
> >>      int count;
> >>      while(s[i]!='\0')
> >>      {
> >>           if(s[i] == s[i+1])
> >>           {
> >>               count = strlen(s)-2;
> >>               while(count--)
> >>               {
> >>                    s[i]=s[i + 2];
> >>                    i++;
> >>               }
> >>               s[i]='\0';
> >>               i=0;
> >>           }
> >>          else
> >>          {
> >>              i++;
> >>          }
> >>      }
> >>      printf("%s",s);
> >>      getch();
> >> }
>
> >> I/P:  DGGDBCBHH  O/P: BCB
>
> >> Best Regards
> >> Abhijit
>
> >> On Sun, Feb 6, 2011 at 1:47 PM, ramkumar santhanam <
> >> [email protected]> wrote:
>
> >>> use stack.
>
> >>>  --
> >>> You received this message because you are subscribed to the Google Groups
> >>> "Algorithm Geeks" group.
> >>> To post to this group, send email to [email protected].
> >>> To unsubscribe from this group, send email to
> >>> [email protected].
> >>> For more options, visit this group at
> >>>http://groups.google.com/group/algogeeks?hl=en.
>
> >>  --
> >> You received this message because you are subscribed to the Google Groups
> >> "Algorithm Geeks" group.
> >> To post to this group, send email to [email protected].
> >> To unsubscribe from this group, send email to
> >> [email protected].
> >> For more options, visit this group at
> >>http://groups.google.com/group/algogeeks?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> Tushar Bindal
> Computer Engineering
> Delhi College of Engineering
> Mob: +919818442705
> E-Mail : [email protected], [email protected]

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

Reply via email to