StoreHub interview question

Solve valid parenthesis leetcode question