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?
- A. 5
- B. 3
- C. 6
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the minimum number of brackets that must be inserted into ())(()(( to make it a balanced sequence?
- What is the length of the longest valid (well-formed) parentheses substring of )()())?
- Starting from an empty deque, the operations are: push front 1, push back 2, push front 3, pop back, push back 4. Let the deque contents…
- A robot starts at position 0 on a number line. For each move it steps right (R) or left (L). Count the number of distinct positions…
- A text cursor starts after the text abc (cursor at the end). Operations in order: type x, Left, Left, Backspace, Right, type y. Here Left…
- How many integers x with 1 <= x <= 500 satisfy x mod 7 = x mod 11?