856. Score of Parentheses

Practice Score of Parentheses for free on NudgeCode: Medium, Stack pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

s is a balanced string of ( and ). Its score is defined recursively:

Return the score of s.

Example

s = "()()"      ->  2
s = "(()())"    ->  4
s = "(()(()))"  ->  6

Constraints