Data Structures & AlgorithmsHardGATE CS · TCS NQT
A string of brackets is ')))(()(' where '(' opens and ')' closes. What is the minimum number of brackets that must be removed to make the string balanced?
- A. 5
- B. 6
- C. 7
- D. 9
Correct answer: A. 5
Unmatched closing brackets are counted when no open bracket is available, and unmatched open brackets remain on the stack at the end; both must be removed.
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
- How many elements of [2, 5, 1, 4, 3] have no strictly smaller element anywhere to their right?
- Three processes arrive at time 0 with bursts 5, 2 and 7. Round-robin uses quantum 3 and the queue starts as P1, P2, P3. Which process…
- A list holds 1 to 10 in order. All nodes whose value is prime are deleted. What is the sum of the remaining values?
- How many index pairs i < j in [1, 2, 3, 4, 5, 6, 7, 8] satisfy (a[i] + a[j]) divisible by 4?
- For the array [1, 2, 2, 3], how many distinct sums a[i] + a[j] are formed by pairs with i not equal to j (ordered pairs)?
- How many distinct values in [1, 1, 2, 2, 2, 3, 4, 4] occur more than one third of the time (count times 3 greater than n)?