In this lesson, we’re going to determine whether or not a set of brackets are balanced or not by making use of the stack data structure that we defined in the previous lesson.
Let’s first understand what a balanced set of brackets looks like.
A balanced set of brackets is one where the number and type of opening and closing brackets match and that is also properly nested within the string of brackets.
Examples of Balanced Brackets
{ }
{ } { }
( ( { [ ] } ) )
Examples of Unbalanced Brackets#
( ( )
{ { { ) } ]
[ ] [ ] ] ]