Use a stack to store the index for each open paren.
When a close paren is encountered, pop one off the stack. If there is
nothing in the stack, remember the index of that close paren.
When you have processed the entire string, if there is anything left
on the stack, the bottom item is the first unmatched open paren.
Compare the index of the first unmatched close paren and open paren
and report the smaller one.
Don

On Dec 20, 8:40 am, zeroByZero <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.
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