Question bank › Math
Dsa Math Medium

Balanced Parentheses Score

You need to evaluate the score of a sequence of balanced parentheses. Each pair of parentheses '()' contributes a score of 1, and each pair of parentheses that is immediately inside another pair contributes double the score of the outer pair. For instance, '()' has score 1, '(())' has a score of 2, and '(()())' has a score of 3. Input a single line containing a string of parentheses. Output the total score of the sequence. Example Input: (()(())) Example Output: 6

Key concepts

parenthesesscoringstack

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.