DXC Technology interview question

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