Purushottam Rathore

Purushottam Rathore

  • 217
  • 8.7k
  • 8.8m

Balanced Brackets Problem

Jun 9 2022 3:40 PM

A bracket is considered to be any one of the following characters: (, ), {?, }?, [, or ] and matching or pair of brackets are () or {?}? or [].
You are required to check if the expression is balanced, i.e. closing brackets and opening brackets match up well. Write a function that takes a string input containing a sequence of brackets, and returns a boolean indicating whether those brackets are balanced. You can assume the input string only contains valid bracket characters.
Examples:

Input: "{?{?[[(())]]}?}?"
Output: true

Input: "({?])"
Output: false

Input: "{?[]()[()]}?"
Output: true

Input: "[(])"
Output: false

 


Answers (1)