Algorithm of 673 - Parentheses Balance

Problem Description Link
This problem is a easy problem. You can solve this problem using stack just follow this stapes
1. get input string for parenthesis.
2. Check, input is opening bracket then push in stack.
3. if  input is closing bracket then compare with top of the stack element
       if valid expression then input and stack top element same type opening and closing bracket
         ie. input= ")" then top= "(" or input= "]" then top= "["

4. Other wise The given expression is invalid
5. if valid print "Yes"
6. if invalid print "No"

N.B: If input is blank character or space then ignore it.
image

No comments:

Post a Comment

Write your comment - Share Knowledge and Experience