Balanced Brackets

Collapse Content

There are 3 kinds of Brackets: [] {} (). Given a String of characters, check if all the brackets in the String are Balanced. A string is balanced if all the start and end brackets are in a correct order so they match each other.

Here are some balanced Strings:

  • {}
  • (hello)[world]
  • [({}{}{})([])]

Here are some Unbalanced ones:

  • (hello - no ending )
  • ([)] - The [ is improperly enclosed in the ().
  • )( There's an ending ) without a ( before it.

I/O Format
The first line of input contains a number t. t lines of text follow. Print true if a line is balanced and false otherwise. Print each result on its own line.


Given a String, print true if the its balanced and false otherwise.

Please sign in or sign up to submit answers.

Alternatively, you can try out Learneroo before signing up.

Contact Us
Sign in or email us at [email protected]