The input to this problem consists of a string containing only the characters (
, )
, {
, }
, [
and ]
. The string may be up to 1000 characters long and is terminated by a newline character.
Write a function that checks if the string is balanced. A string is balanced if all brackets are closed in the correct order. For example, ([])
is balanced, but ([)]
is not. The function should return YES
if the string is balanced and NO
otherwise.
Input: ([])
Output: YES
Input: ([)]
Output: NO
Input: {[()]()}
Output: YES
Input: {[()}()
Output: NO
Input: {{[[({(){}})[]]]}}
Output: YES