Data Structures & AlgorithmsModerateGATE CS · TCS NQT

What is the minimum number of brackets that must be removed from ')()())(()' to make it a balanced sequence?

  1. A. 4
  2. B. 3
  3. C. 5
  4. D. 7

Correct answer: B. 3

Greedy matching leaves two unmatched ')' (the first and the sixth characters) and one unmatched '(' near the end; all three must be removed.

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

Exams that ask this topic