Sail E0 Webinar
Question
Write a piece of code which returns true if the string contains balanced parenthesis, false otherwise.
Options:
A .  public boolean isBalanced(String exp){
B .  public boolean isBalanced(String exp){
C .  public boolean isBalanced(String exp){
D .  public boolean isBalanced(String exp){
Answer: Option A


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 ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers