#K65907. Balanced Brackets Checker
Balanced Brackets Checker
Balanced Brackets Checker
In this problem, you are given a string that may contain various types of brackets along with other characters. Your task is to determine whether the sequence of brackets is balanced.
A string is said to be balanced if every opening bracket ((
, [
, or {
) is properly closed by a matching closing bracket ()
, ]
, or }
) in the correct order. For example, the string {[()]}
is balanced, while {[(])}
is not.
The formal condition for a sequence to be balanced can be expressed in \(\LaTeX\) as follows:
\( S \text{ is balanced if } S = \epsilon \; \text{or} \; S = \text{left} + S + \text{right} \)
Note: Characters that are not brackets should be ignored.
inputFormat
The input consists of a single line which is a string that may include spaces and other characters. This string should be checked for balanced brackets.
outputFormat
Output a single line: True
if the brackets in the input string are balanced, otherwise False
.
{[()]}
True