You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For a given expression in the form of a string, find if there exist any redundant brackets or not. It is given that the expression contains only rounded brackets or parenthesis and the input expression will always be balanced.
2
+
A pair of the bracket is said to be redundant when a sub-expression is surrounded by unnecessary or needless brackets.
3
+
Example:
4
+
Expression: (a+b)+c
5
+
Since there are no needless brackets, hence, the output must be 'false'.
6
+
7
+
Expression: ((a+b))
8
+
The expression can be reduced to (a+b). Hence the expression has redundant brackets and the output will be 'true'.
9
+
Note:
10
+
You will not get a partial score for this problem. You will get marks only if all the test cases are passed.
11
+
Input Format :
12
+
The first and the only line of input contains a string expression, without any spaces in between.
13
+
Output Format :
14
+
The first and the only line of output will print either 'true' or 'false'(without the quotes) denoting whether the input expression contains redundant brackets or not.
15
+
Note:
16
+
You are not required to print the expected result. It has already been taken care of.
17
+
Constraints:
18
+
0 <= N <= 10^6
19
+
Where N is the length of the expression.
20
+
21
+
Time Limit: 1 second
22
+
Sample Input 1:
23
+
a+(b)+c
24
+
Sample Output 1:
25
+
true
26
+
Explanation:
27
+
The expression can be reduced to a+b+c. Hence, the brackets are redundant.
0 commit comments