Skip to content

Practice Score of Parentheses

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#856
LeetCode Problem

Score of Parentheses

Problem Statement

Return the score of balanced parentheses string s. A single pair () scores 1. Concatenating two balanced strings adds their scores, while enclosing a nonempty balanced string in another pair of parentheses doubles its score.

Source: Score of Parentheses on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "()"
Output
1

# Example 2

Input
s = "(())"
Output
2

# Example 3

Input
s = "()()"
Output
2

Constraints

2 <= s.length <= 50
s consists of only '(' and ')'.
s is a balanced parentheses string.

Related LeetCode Problems

Practice more problems similar to Score of Parentheses.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.