Uber interview question

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