#K82277. Balanced Parentheses Checker
Balanced Parentheses Checker
Balanced Parentheses Checker
You are given a string s
consisting of lowercase English letters and parentheses (')
and ')'
. Your task is to determine if the parentheses in the string are balanced and correctly nested.
A string is considered valid if:
- Every opening bracket \( ( \) has a corresponding closing bracket \( ) \).
- The brackets are correctly nested. In other words, for every prefix of the string, the number of opening brackets is not less than the number of closing brackets.
For example, the string a(b)c(d)e
is valid, while a(b(c)d
and (a(b)c)d)
are not valid.
Note: All formulas or special symbols are provided in \(\LaTeX\) format for clarity.
inputFormat
The input consists of a single line containing a string s
which may be empty. The string is composed of lowercase letters and the characters '(' and ')'.
Input is read from standard input (stdin).
outputFormat
Output a single line: True
if the input string has balanced parentheses, and False
otherwise.
Output should be written to standard output (stdout).
## samplea(b)c(d)e
True