brackets made of ( and ). Its worth is defined as follows:
- an empty pair () is worth 1;
- two balanced strings written one after another are worth the sum of their worths;
- a balanced string wrapped in one more pair of brackets is worth twice as much as without the wrapper.
Return the worth of brackets.brackets="()(())" → 3
() is worth 1, (()) is worth 2 · 1 = 2, together 1 + 2 = 3.
brackets="((())())" → 6
Inside the outer pair sit (()) = 2 and () = 1, so the total is 2 · (2 + 1) = 6.
brackets contains only ( and )brackets is balancedbrackets="()(())"
3
Run checks the first 3 tests in your browser. Submit checks all 57 tests on the server, hidden ones included.