FunctionRacerProblemsRace

Score of Parentheses

MediumStacks and queuesPython, JavaScript, TypeScript, Java, C++

s is a balanced parentheses string. Its score follows these rules:

Return the score of s.

Example 1

s "()()"
returns 2

1 + 1 = 2.

Example 2

s "(()(()))"
returns 6

2 * (1 + 2 * 1) = 6.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Stacks and queues problems