Question
Write a piece of code which returns true if the string contains balanced parenthesis, false otherwise.
Answer: Option A
Was this answer helpful ?
Whenever a '(' is encountered, push it into the stack, and when a ')' is encountered check the top of the stack to see if there is a matching '(', if not return false, continue this till the entire string is processed and then return true.
Was this answer helpful ?
Submit Solution