#K54732. Redundant Parentheses Detector
Redundant Parentheses Detector
Redundant Parentheses Detector
You are given a valid mathematical expression in the form of a string. Your task is to detect whether the expression contains any redundant parentheses.
Redundant parentheses are unnecessary and do not affect the order of operations. For an expression to have redundant parentheses, a set of parentheses should enclose an expression without containing any operator that makes them necessary.
For example, in the expression \( (a+b) \), the parentheses are not redundant because they enclose the entire operation. However, in \( ((a+b)) \) the outer parentheses are redundant because they do not change the evaluation order.
Your goal is to output True
if the expression contains redundant parentheses, and False
otherwise.
inputFormat
The input consists of a single line containing a valid mathematical expression. The expression can contain letters, operators (+, -, *, /), spaces, and parentheses.
Note: The input is provided via standard input (stdin).
outputFormat
Output a single line with either True
if the expression contains redundant parentheses, or False
if it does not. The output should be printed to standard output (stdout).
(a + b)
False