← back to unit
Medium
# stacks medium
Nested Boxes
A box in a box in a box… how deep does the wrapping go? 📦
You get a balanced string of ( and ) where each ( opens a box and ) closes one. Print the deepest nesting level (an empty string is depth 0).
Example:
Input: boxes = "(())()"
Output: 2
The depth climbs to 1, then 2, inside the first group before descending back to 0, then rises to 1 in the second group — the deepest point ever reached is 2.
💡 need a hint?
stk-nested-boxes.py🔒 given lines are locked — write your code in between
loading...