Peak depth times group count of a bracket scan
You validate the bracket string {[()]}[{}] with the standard stack method (push each opener, pop on each matching closer). Let be the maximum number of items on the stack at any instant, and let be the number of times the stack returns to empty during the scan. Report the product .
Show hints (2)+
- Stack size = current nesting depth; its peak is .
- Each time the stack returns to empty ends one top-level group; count those for , then multiply.
Answer
Reveal answer →Final answer
6
Want the full step-by-step worked solution? It's part of Premium - along with a worked solution for every question in the bank.
Asked at: Probability & Market-Making, Game-Based Aptitude