Interview Questions/Coding/Score The Signal Brackets

Score The Signal Brackets

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Score The Signal Brackets

A signal is written using only balanced parentheses. Each smallest pair "()" has score 1. If two balanced parts are placed next to each other, their scores add up. If one balanced part is wrapped inside another pair of parentheses, its score is doubled. Return the total score of the given parentheses signal.

Examples

Example 1
Input:
()
Output:
1

Explanation: A single pair has score 1.

Approach hint

Use the stack to store the score before entering a new pair of parentheses.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp