Amazon Interview Question

Valid Brackets problem.