Data Structures & AlgorithmsVery hard
In the string "((a)(b(c)))d((e))", what is the maximum nesting depth of round brackets (the number of brackets open at the deepest point)?
- A. 3
- B. 6
- C. 2
- D. 4
Correct answer: A. 3
Track the current open count while scanning and record its maximum; the answer is the peak depth, not the number of brackets. Counting all open brackets or the final depth misses the nesting structure.
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 contiguous subarrays of 1 4 2 6 3 5 have an AVERAGE that is at least 3?
- What is the maximum sum of a contiguous subarray of -3 4 -1 2 5 -6 3 1 whose LENGTH is between 2 and 3 inclusive?
- How many contiguous subarrays of 5 1 9 4 8 3 7 have (maximum − minimum) at least 3?
- What is the length of the shortest contiguous subarray of 2 1 2 3 1 3 2 1 that contains EVERY distinct value appearing in the array?
- What is the length of the longest contiguous subarray of 2 3 4 5 7 8 9 10 1 that contains at most 2 odd numbers?
- How many pairs of positions i < j in 2 3 4 6 8 9 12 satisfy that A[j] is divisible by A[i]?