Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

$\huge\color{cadetblue}{\text{Balanced brackets}}$


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.


$\color{darkseagreen}{\text{\Large Examples}}$

Input: ([])
Output: YES

Input: ([)]
Output: NO

Input: {[()]()}
Output: YES

Input: {[()}()
Output: NO

Input: {{[[({(){}})[]]]}}
Output: YES