Data Structures & AlgorithmsModerateIBM · Deloitte pattern

A stack-based checker is run on four strings. Which one is balanced?

  1. A. (()[]{}
  2. B. {[}]()
  3. C. ([)]{}
  4. D. {[()()]}[(())]

Correct answer: D. {[()()]}[(())]

In ([)]{} the ) arrives while [ is on top; {[}] has the same crossing; (()[]{} ends with one ( left on the stack. Only {[()()]}[(())] closes every bracket in reverse order of opening. Equal counts of each bracket type are not enough.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic