Data Structures & AlgorithmsHardGATE CS · ICPC regional
How many valid (balanced) bracket sequences of length 8 are there using one type of bracket?
- A. 15
- B. 16
- C. 14
- D. 18
Correct answer: C. 14
Balanced sequences of 2n brackets are counted by the Catalan number C_n, here C4 = 14. Counting all 2^8 strings ignores the balance rule.
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
- A grid has the rows ..#.., .##.., ....., #.#.# (where '.' is open and '#' is a wall; all rows have length 5). Starting from the top-left…
- A list holds 1, 1, 2, 2, 2, 3, 1, 1. Consecutive duplicates are merged into one node each. What is the sum of the values left in the list?
- How many distinct strings can be obtained from abc by swapping two adjacent characters at most once (including the original string)?
- A passenger count changes by +3, -1, +2, -2, +4, -3 at successive stops, starting from 0. What is the maximum number of passengers on…
- How many integers x in [1, 500] have digit sum equal to 10?
- How many unordered pairs {a, b} with a < b and 1 <= a, b <= 30 have a b a perfect square?