Then what's your output for test case "()(()"?

On 2011-12-22 12:45, atul anand wrote:
i guess there is no need of stack , we can take a variable say top;

increment top when open bracket occur "(" and decrement when close bracket ")" occurs.

keep track of first close bracket mismatch i.e when top is zero and current bracket is ")".

if top!=0
       report min(index,top);

On Tue, Dec 20, 2011 at 11:06 PM, shady <sinv...@gmail.com <mailto:sinv...@gmail.com>> wrote:

    true, we have to look at the entire string to find the first mismatch,
    and its meaning depends on how you interpret it... either way stack
    will solve it :)

    On Dec 20, 10:32 pm, Arun Vishwanathan <aaron.nar...@gmail.com
    <mailto:aaron.nar...@gmail.com>> wrote:
    > @shady: I guess first mismatch means the innermost open brace
    that doesnt
    > have a close brace. U cannot know that the first brace does not
    have a
    > closing one unless u look at the entire string.
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > On Tue, Dec 20, 2011 at 9:23 AM, shady <sinv...@gmail.com
    <mailto:sinv...@gmail.com>> wrote:
    > > ( ( ) ( ( ) ( ( ) ) (  )  for this SAMM faulty index is 0,
    because the
    > > first bracket has itself found no matching....
    >
    > > @atul
    > > ( ( ( () ) ) for this first bracket is faulty as it couldn't
    find a
    > > closing bracket, , ,
    > > you can keep a stack with map as element
    > > stack< map<int, char> >
    >
    > > map<int, char> where integer is the index of the bracket,
    which is stored
    > > as char
    > > idea is similar to don's.
    >
    > > On Tue, Dec 20, 2011 at 10:42 PM, atul anand
    <atul.87fri...@gmail.com <mailto:atul.87fri...@gmail.com>>wrote:
    >
    > >> there are multiple mismatch or only one mis-match in the
    input string.
    >
    > >> if the given string as below :-
    >
    > >> ( ( ( () ) ) -> for this is missing match is for 1st , 2nd or 3rd
    > >> bracket.
    >
    > >> what would be the answer for this.
    >
    > >> On Tue, Dec 20, 2011 at 8:10 PM, zeroByZero
    <shri.nit...@gmail.com <mailto:shri.nit...@gmail.com>>wrote:
    >
    > >>> In a given string arrary arr[] = "((()())" or any other
    string return
    > >>> index for which no match is found as for this example is
    index 0 and
    > >>> for "()()()(()" is index 6
    >
    > >>> --
    > >>> 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 <mailto:algogeeks@googlegroups.com>.
    > >>> To unsubscribe from this group, send email to
    > >>> algogeeks+unsubscr...@googlegroups.com
    <mailto:algogeeks%2bunsubscr...@googlegroups.com>.
    > >>> 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
    algogeeks@googlegroups.com <mailto:algogeeks@googlegroups.com>.
    > >> To unsubscribe from this group, send email to
    > >> algogeeks+unsubscr...@googlegroups.com
    <mailto:algogeeks%2bunsubscr...@googlegroups.com>.
    > >> 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
    algogeeks@googlegroups.com <mailto:algogeeks@googlegroups.com>.
    > > To unsubscribe from this group, send email to
    > > algogeeks+unsubscr...@googlegroups.com
    <mailto:algogeeks%2bunsubscr...@googlegroups.com>.
    > > For more options, visit this group at
    > >http://groups.google.com/group/algogeeks?hl=en.
    >
    > --
    >  "People often say that motivation doesn't last. Well, neither
    does bathing
    > - that's why we recommend it daily."

    --
    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
    <mailto:algogeeks@googlegroups.com>.
    To unsubscribe from this group, send email to
    algogeeks+unsubscr...@googlegroups.com
    <mailto:algogeeks%2bunsubscr...@googlegroups.com>.
    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 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.

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