Uber Interview Question

Round 5(1 hr): valid parenthesis problem with some modifications