Pergunta de entrevista da empresa DXC Technology

I was asked to solve a coding question about balancing the brackets.