Exercise: Balanced Brackets

Check if the brackets in a string are balanced.

Problem statement

Given a string containing only square brackets, [] you are required to check whether the brackets are balanced or not. The brackets are said to be balanced if, for every opening bracket, there is a closing bracket after it. You will write your code in the check_balance() function, which returns True if the brackets are balanced and False if they are not. For an empty string, the function will return True. For the sake of simplicity, you can assume that the string will not contain any other characters.

Get hands-on with 1400+ tech skills courses.