I guess

"a, x, y, a"

is the only case where anish's algo fails.. because in every other case the
repeated digit will either be consecutive or alternative..  So, it will be
better to pre-check this condition and apply the above algo.. Please do give
any suitable example to contradict.

regards


On Sat, Aug 7, 2010 at 5:32 PM, Dave <[email protected]> wrote:

> @Anish: Does it work on 1,2,3,1?
>
> Dave
>
> On Aug 7, 2:04 am, Ashish Goel <[email protected]> wrote:
> > I thought again on this, i think we have made a simple problem quite
> > complicated
> >
> > if a number is half times in a list, that  implies that either it is
> > repeated alternately otherwise adjacent somewhere else
> >
> > so if this is repeating alternatively that in first 4 occurrence, we
> should
> > have this at index 0,2 or 1,3 otherwise it is adjacent somewhere else
> >
> > additional case(1,2,3,3,4,3,6,3) also covered
> >
> > therefore
> >
> > if ((a[0] ==a[1]) || (a[0]==a[2])) { printf("%d",a[0]);  return;}
> > if ((a[1] ==a[2]) || (a[1]==a[3])) { printf("%d",a[1]);  return;}
> >
> > for (int i=3;i<n;i++)
> >
> > {
> >     if a[i]==a[i-1] printf("%d", a[i]); return;
> >
> > }
> >
> > Best Regards
> > Ashish Goel
> > "Think positive and find fuel in failure"
> > +919985813081
> > +919966006652
> >
> >
> >
> > On Sat, Aug 7, 2010 at 11:50 AM, Ashish Goel <[email protected]> wrote:
> > > 1,6,3,4,6,5,6,2,6,6
> > > or
> > > 1,2,3,6,4,6,5,6,6,6
> >
> > > lovely...
> >
> > > Use a two-step process. First, check for a repeated number in the
> > >> first 4 elements. If none is found, then there are at least n/2-1
> > >> occurrences of the repeated elements in the last n-3 elements, meaning
> > >> that there must be at least two repeated elements in adjacent
> > >> positions. So second, check for equal adjacent numbers in the last n-3
> > >> elements.
> >
> > >> Dave
> >
> > >> On Aug 5, 8:36 am, AlgoBoy <[email protected]> wrote:
> > >> > an array in which n/2 elements are unique...and the remaning n/2
> have
> > >> > the same elements but reapeated n/2 times. can anyone suggest a
> linear
> > >> > solution with constant space/...
> >
> > >> --
> > >> 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]<algogeeks%[email protected]>
> <algogeeks%2bunsubscr...@googlegroups­.com>
> > >> .
> > >> For more options, visit this group at
> > >>http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text -
> >
> > - Show quoted text -
>
> --
> 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]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


AD

-- 
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