GATE Computer ScienceHardGATE CS (PYQ pattern)

A bracket checker pushes every opening bracket and, on a closing bracket, pops and compares. For the string {[()()]([{}])}[({[]}) the checker ends with the stack not empty. How many symbols remain on the stack at the end, and what is the greatest stack height reached during the scan?

  1. A. 1 remaining, maximum height 4
  2. B. 2 remaining, maximum height 4
  3. C. 1 remaining, maximum height 5
  4. D. 0 remaining, maximum height 4

Correct answer: A. 1 remaining, maximum height 4

The first block {[()()]([{}])} is balanced (its deepest point is the stack { ( [ { of height 4). In the final block [({[]}) the ) closes ( but the opening [ is never closed, so exactly one symbol remains.

More Programming and Data Structures (GATE) questions

Exams that ask this topic