Pergunta de entrevista da empresa Marvell Technology

Given an expression with brackets, Suggest a solution to check legality: Examples: ((), )(), (((} , {[()]