Given a string containing parentheses, determine whether the parentheses are balanced (valid). The base version uses only '()'. The follow-up…