Data Structures & AlgorithmsVery hardTCS NQT · Infosys

The string (()(()(( is scanned left to right: '(' opens and ')' closes the most recent unmatched '('. How many characters are unmatched in total?

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

Correct answer: D. 4

Count the unmatched closing brackets plus the open brackets left on the stack at the end. Only one of the two groups is counted if you forget the stack's final size.

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

Exams that ask this topic