EPAM Systems interview question

How to validate string with brackets so they are valid