We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
JavaScript Solution:
========= PSEUDOCODE ==========
1. Take one empty stack and a variable name valid with true initial value
2. Travell to each bracket of the input
3. if we are having left bracket push it into the stack
4. if we are having right bracket , then pop a bracket from the stack.
. check if the poped bracked and the right bracket are compliment to eachother or not OR check stack is empty , and update the variable valid accordingly.
. complete it for all three type of right bracket
5. if valid == true and stack is empty return 'YES' otherwise return 'NO'.
Stacks: Balanced Brackets
You are viewing a single comment's thread. Return to all comments →
JavaScript Solution: ========= PSEUDOCODE ========== 1. Take one empty stack and a variable name valid with true initial value 2. Travell to each bracket of the input 3. if we are having left bracket push it into the stack 4. if we are having right bracket , then pop a bracket from the stack. . check if the poped bracked and the right bracket are compliment to eachother or not OR check stack is empty , and update the variable valid accordingly. . complete it for all three type of right bracket 5. if valid == true and stack is empty return 'YES' otherwise return 'NO'.
Here is working code :