Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Score of Parentheses

Medium

Topics
StringStack

Given a balanced parentheses string s, compute its score: () is 1, AB is A+B, and (A) is 2*A.

Example 1

Input:  s = "()"
Output: 1

Example 2

Input:  s = "(())"
Output: 2

Example 3

Input:  s = "()()"
Output: 2

Example 4

Input:  s = "(()(()))"
Output: 6

Constraints

  • 2 <= s.length <= 50
  • s is a balanced parentheses string.
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access