Question bank › Recursion
Dsa Recursion Hard

The Recursive Bracket Weight

A balanced bracket string's weight is calculated recursively. The weight of a pair of brackets at nesting depth $D$ (where the outermost pair is depth 1) is $D \times (\text{sum of weights of immediate inner pairs} + 1)$. The total weight of a string is the sum of weights of all top-level bracket pairs. Example: `()()` is $1(0+1) + 1(0+1) = 2$. Example: `(())` is $1(W(\text{'()'}) + 1) = 1(2(0+1) + 1) = 3$. Given a balanced bracket string, find its total weight.

Key concepts

recursionparsingtrees

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 InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.