Re: [algogeeks] Re: Return index of first mismatch bracket ( or )
And I think the comparing between first unmatched open/close bracket index is not needed. If we found an unmatched close bracket (ie. the stack is empty when encounter a close bracket), we could return current index immediately, since all open brackets before that position are matched and popped out. If we could not find an unmatched close bracket, and the stack is not empty, we examine the stack and return the bottom index (the left most unmatched), or the top index (the inner most unmatch) as needed. On 2011-12-22 13:27, Terence wrote: 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 mapint, char mapint, 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.comwrote: 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.comwrote: 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
Re: [algogeeks] Re: Return index of first mismatch bracket ( or )
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 mapint, char mapint, 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.comwrote: 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.comwrote: 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.
[algogeeks] Re: Return index of first mismatch bracket ( or )
#includestdio.h#includestring.h#define maxsize 100 struct stack{ int A[maxsize]; int top;}; struct stack s;void push(int index){ s.top++;if(s.top==maxsize) { printf(cannot be pushed); } else{ s.A[s.top]=index; }} int pop(){ int a; a=s.top;s.top--;if(a==-1) { return -1; } else { return s.A[a]; } } int main(){ int i=0,res;char str[100]; scanf(%s,str);s.top=-1; for(i=0;istrlen(str);i++) { if(str[i]=='(') { push(i);} else{ res=pop(); } } res=pop(s); if(res!=-1) printf(mismatch found at index %d \n,s.A[0]);} On Dec 20, 7:40 pm, 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.
Re: [algogeeks] Re: Return index of first mismatch bracket ( or )
@venky : u call this code??? On Thu, Dec 22, 2011 at 7:44 PM, venky mankenavenkat...@gmail.com wrote: #includestdio.h#includestring.h#define maxsize 100 struct stack{ int A[maxsize]; int top;}; struct stack s;void push(int index){ s.top++;if(s.top==maxsize) { printf(cannot be pushed); } else{ s.A[s.top]=index; }} int pop(){ int a; a=s.top;s.top--;if(a==-1) { return -1; } else { return s.A[a]; } } int main(){ int i=0,res;char str[100]; scanf(%s,str);s.top=-1; for(i=0;istrlen(str);i++) { if(str[i]=='(') { push(i);} else{ res=pop(); } } res=pop(s); if(res!=-1) printf(mismatch found at index %d \n,s.A[0]);} On Dec 20, 7:40 pm, 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. -- 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.
Re: [algogeeks] Re: Return index of first mismatch bracket ( or )
got it :) On Thu, Dec 22, 2011 at 10:57 AM, Terence technic@gmail.com wrote: 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 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 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 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 mapint, char mapint, 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.comwrote: 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 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. -- 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. -- 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. 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. -- 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.
Re: [algogeeks] Re: Return index of first mismatch bracket ( or )
@Terence : got it :) :) ...inc/dec wont work On Thu, Dec 22, 2011 at 10:57 AM, Terence technic@gmail.com wrote: 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 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 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 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 mapint, char mapint, 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.comwrote: 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 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. -- 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. -- 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. 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. -- 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.
Re: [algogeeks] Re: Return index of first mismatch bracket ( or )
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 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 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 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 mapint, char mapint, 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 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 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. -- 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. -- 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. 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.
[algogeeks] Re: Return index of first mismatch bracket ( or )
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.
[algogeeks] Re: Return index of first mismatch bracket ( or )
This can be done using Stack . For example :- you have got the pattern :- 0 1 2 3 4 5 6 7 8 9 10 11 ( ( ) ( ( ) ( ( ) ) ( ) ... this pattern is wrong the faulty index is at index 3 . void MatchingBracket( char *str ) { while ( str[i++] != '\0' ) { if ( str[i] == '(') push(i); // If '(' is encountered the push the index else if (str[i]== ')') pop (); // if ')' the pop the stack } // if stack empty the no suck index else print the top of the stack if(top=0) printf(%d ,stack[top]); } It will give the faulty index as 3rd one . Note :- This code is not tested -- 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.
[algogeeks] Re: Return index of first mismatch bracket ( or )
Continued . Forgot to metion to also keep track of the index of the Closing first bracket ( If tht closing doesn't hav matching opening bracket on it's left ) and at last check for the top of the stack(If present) and the index(if present) . And print the minimum index value of the Stack[top] and Index of the closing bracket . Index = The index of the closing bracket . Minimum (stack[top],index) . -- 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.
[algogeeks] Re: Return index of first mismatch bracket ( or )
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 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 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 mapint, char mapint, 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.comwrote: 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.comwrote: 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. -- 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. -- 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. 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.