Z25

Score of Parentheses

Mid / Senior Engineer
Target Time: 25 - 35 Minutes
Type: NUMERIC

Problem Statement & Objective

Given a balanced parentheses string s, return the score of the string based on nesting rules: () has score 1, AB has score A + B, and (A) has score 2 * A.

Function Signature (Python)

score_of_parentheses(s: str) -> int

Input & Output Contract

Output Rule:Hesaplanan skor tam sayısı.

System Constraints

2 <= s.length <= 50
s dengeli parantez metnidir

Example Execution Walkthrough

s = '(()(()))' -> ( 1 + (1) ) = ( 1 + 2 ) = (3) = 6

Example Test Scenarios (3)

Example 1
Input:["()"]
Expected Output:1
Example 2: 2 * 1
Input:["(())"]
Expected Output:2
Example 3: 1 + 1
Input:["()()"]
Expected Output:2
Loading Python Editor...
Input Parameters
[
  "()"
]
Expected Output
1