data-structures-and-algorithms

Challenge Title

stack-queue-brackets

Whiteboard Process for stack-queue-brackets_useing stack

stack-queue-brackets_useing stack)

Whiteboard Process for stack-queue-brackets_with out stack

 stack-queue-brackets_with out stack

Approach & Efficiency

Approach

  1. Initialize a counter variable, balance, to 0.

  2. Iterate over each character in the input string:
    • If the character is an opening bracket ((, {, or [), increment balance by 1.
    • If the character is a closing bracket (), }, or ]), decrement balance by 1.
      • If balance becomes negative, return False immediately since the brackets are not balanced.
  3. Return True if balance is 0, indicating that the brackets are balanced. Otherwise, return False.

Efficiency

Solution

stack-queue-brackets_useing stack stack-queue-brackets_with out stack