EPAM Systems Interview Question

How to validate string with brackets so they are valid