Qualcomm interview question

Hackerrank: Balanced brackets