PTC Interview Question

Similar to the balanced parenthesis problem.