Question: Question 1 . Write this code in c . The deepest substring of a string containing text in nested parenthesis is the substring which is

Question 1.Write this code in c.
The deepest substring of a string containing text in nested parenthesis is the substring which is enclosed in the maximum number of parenthesis. For example, the deepest substring of a+((b+c)+d) is b+c.
Your program should take as input a string containing nested parenthesis and print out its deepest substring. If there is more than one substring at the deepest level then your program should output the first one. For example, on input a+((b+c)+(d+e)) your program should output b+c.
You can assume the input string will contain at most 1000 characters that are only letters or parentheses (i.e., no spaces) and contains balanced parentheses (every open parenthesis has a corresponding closing parenthesis). You should read the input via standard input and print out nothing except the deepest substring followed by a newline.
Note. Your implementation must run in O(n) operations where n is the length of the input string.
input: a+((b+c)+d)
output: b+c
input: a+((b+c)+(d+e))
output: b+c
input: a+((b+(c+d))+(e+f))
output: c+d
input: noparenthesis
output: noparenthesis
input: ((()))
output:
input: (aa)(bb)(cc)(dd)
output: aa
input: (a)((b))(((c)))((((d))))
output: d
input: (a(b(c(d(e)))))
output: e

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!