Data Structures & AlgorithmsModerate
What is the length of the longest contiguous substring of "([)][]()[[]]" that is a balanced bracket sequence, where '(' must close with ')' and '[' must close with ']' and brackets nest properly?
- A. 8
- B. 10
- C. 12
- D. 7
Correct answer: A. 8
Test each substring with a typed stack: an opening bracket is pushed and a closing bracket must match the top. A balanced block must match type as well as count, so mismatched pairs such as '(]' never count.
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 substrings of "(()())(())((()))" are balanced round-bracket sequences whose maximum nesting depth is at most 2?
- What is the length of the longest contiguous substring of "xxyxyyxyxxy" in which the number of 'x' letters is at most the number of 'y'…
- Sort 4 7 4 2 7 2 9 4 3 so that values with higher FREQUENCY come first; values with equal frequency are ordered by value ascending, and…
- In the sorted array 1 1 1 2 2 3 3 3 3 4, remove the extra copies so that every value appears AT MOST TWICE, keeping the order. What is the…
- In the string "abciiidefoeuxyz", what is the largest number of vowels (a, e, i, o, u) that appear in any contiguous window of length 3?
- What is the length of the longest contiguous substring of "aabbccabcdd" in which EVERY distinct letter appears at least twice?