Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
How many well-formed strings of 3 pairs of parentheses (length 6) exist?
- A. 6
- B. 8
- C. 4
- D. 5
Correct answer: D. 5
The number of balanced sequences with n pairs is the Catalan number C_n, and C_3 = 5. Counting all ways to place 3 opening brackets among 6 positions (20) ignores balance.
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
- On a line with cells 1 to 10, a lamp at position p lights cells p-2 to p+2. Lamps are placed at positions 1, 4, 6, 9. Do they light every…
- The histogram heights [1, 3, 3, 2, 3] describe bars of width 1. What is the area of the largest rectangle that fits under the histogram?
- How many integers from 1 to 50 inclusive have exactly two 1-bits in binary and are even?
- Under the hash h(s) = sum of the character codes of s, how many of the 3-letter strings "abc", "cab", "bac", "xyz", "zyx" share their hash…
- In 3 1 4 4 5 2 6 6 7, an element is a RECORD if it is strictly larger than every element before it (the first element is not counted). How…
- From the array 1 5 3 3 3 7 2 4 6, choose the largest number of PAIRS of positions so that every position is used in at most one pair and…