Pergunta de entrevista da empresa Bloomberg

Implement an algorithm that checks if a sequence of brackets is valid.