`{"id":"3376cafc-535a-43ac-98a2-b725de0babe5","name":"Score Of Parentheses","description":"Given a balanced parentheses string S, compute the score of the string based on the following rule:\r\n () has score 1\r\n AB has score A + B, where A and B are balanced parentheses strings.\r\n (A) has score 2 * A, where A is a balanced parentheses string.\r\n\r\nScore of ()()() string is 3 => 1 + 1 + 1\r\nScore of (()) string is 2 => 2 * 1","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1: S is a balanced parentheses string, containing only ( and ).\r\n2: 2 &lt;= S.length &lt;= 50","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <stack>\nusing namespace std;\n \n// Function to calculate\n// score of parentheses\nlong long scoreOfParentheses(string S)\n{\n // Write your code here \n}\n \n\nint main()\n{\n string S1 ;\n cin>>S1;\n cout << scoreOfParentheses(S1) << endl;\n \n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static int scoreOfParentheses(String S) {\r\n return 0;\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n int score = scoreOfParentheses(read.readLine());\r\n System.out.println(score);\r\n \r\n }\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"(()(()))","sampleOutput":"6\r\n","questionVideo":"https://www.youtube.com/embed/rWsv46ME6lI","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8c6022a5-8654-4226-918f-8110af738bd4","name":"Stacks For Intermediate","slug":"stacks-for-intermediate-688","type":0},{"id":"b741e094-1a08-47d2-9939-09b35cb549c3","name":"Score Of Parentheses","slug":"score-of-parentheses","type":1}],"next":{"id":"178cde19-0d1c-4073-ba53-22a4fdcedd39","name":"Score Of Parentheses Medium MCQ","type":0,"slug":"score-of-parentheses-medium-mcq"},"prev":{"id":"0ab476db-73e0-4d99-a845-1d103b3464ea","name":"Remove outermost parentheses","type":3,"slug":"remove-outermost-parentheses"}}}`

# Score Of Parentheses

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

`{"id":"3376cafc-535a-43ac-98a2-b725de0babe5","name":"Score Of Parentheses","description":"Given a balanced parentheses string S, compute the score of the string based on the following rule:\r\n () has score 1\r\n AB has score A + B, where A and B are balanced parentheses strings.\r\n (A) has score 2 * A, where A is a balanced parentheses string.\r\n\r\nScore of ()()() string is 3 => 1 + 1 + 1\r\nScore of (()) string is 2 => 2 * 1","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1: S is a balanced parentheses string, containing only ( and ).\r\n2: 2 &lt;= S.length &lt;= 50","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <stack>\nusing namespace std;\n \n// Function to calculate\n// score of parentheses\nlong long scoreOfParentheses(string S)\n{\n // Write your code here \n}\n \n\nint main()\n{\n string S1 ;\n cin>>S1;\n cout << scoreOfParentheses(S1) << endl;\n \n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static int scoreOfParentheses(String S) {\r\n return 0;\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n int score = scoreOfParentheses(read.readLine());\r\n System.out.println(score);\r\n \r\n }\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"(()(()))","sampleOutput":"6\r\n","questionVideo":"https://www.youtube.com/embed/rWsv46ME6lI","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8c6022a5-8654-4226-918f-8110af738bd4","name":"Stacks For Intermediate","slug":"stacks-for-intermediate-688","type":0},{"id":"b741e094-1a08-47d2-9939-09b35cb549c3","name":"Score Of Parentheses","slug":"score-of-parentheses","type":1}],"next":{"id":"178cde19-0d1c-4073-ba53-22a4fdcedd39","name":"Score Of Parentheses Medium MCQ","type":0,"slug":"score-of-parentheses-medium-mcq"},"prev":{"id":"0ab476db-73e0-4d99-a845-1d103b3464ea","name":"Remove outermost parentheses","type":3,"slug":"remove-outermost-parentheses"}}}`

Editor

# Score Of Parentheses

medium

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

## Constraints

1: S is a balanced parentheses string, containing only ( and ). 2: 2 <= S.length <= 50

## Format

### Input

Input is managed for you

### Output

Output is managed for you

## Example

Sample Input

`.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}(()(()))`

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}6 ```

Question Video

Discussions

Show Discussion

Related Resources