Score of Parentheses

Given a balanced parentheses string S, compute the score of the string based on the rule: "()" has score 1, AB has score A + B, and (A) has score 2 * A, where A and B are balanced parentheses strings.

Input Format

s = balanced parentheses string

Output Format

score of the string

Constraints

Examples

Example 1:

Input:

s = "()"

Output:

1

Explanation:

"()" has score 1.

Example 2:

Input:

s = "(())"

Output:

2

Explanation:

"(())" has score 2.

Example 3:

Input:

s = "()()"

Output:

2

Explanation:

"()()" has score 1 + 1 = 2.

Example 4:

Input:

s = "(()(()))"

Output:

6

Explanation:

"(()(()))" has score 2 * (1 + 2) = 6.

Loading...
Score of Parentheses - Stack DSA Problem