Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT

What is the minimum number of parentheses that must be ADDED (at any positions) to make "())(()))((" a valid parentheses string?

  1. A. 0
  2. B. 5
  3. C. 6
  4. D. 4

Correct answer: D. 4

Scan with a balance counter: an unmatched ')' costs one insertion, and whatever '(' remain open at the end each need a ')'. The count difference of the two symbols ignores the order, which decides which brackets are unmatched.

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

Exams that ask this topic