Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many strings of length 4 over the alphabet {a, b} contain the letter a somewhere before a b (that is, contain 'a' followed later by 'b' as a subsequence)?
- A. 12
- B. {C+7}
- C. 11
- D. 14
Correct answer: C. 11
Strings with no a before any b are exactly the strings of the form b...ba...a, and there are 5 of those among 16, so the answer is 16 - 5 = 11.
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
- What is the edit distance (Levenshtein distance with insertion, deletion and substitution each costing 1) between intention and execution?
- What is the length of the longest common subsequence of AGGTAB and GXTXAYB (letters need not be contiguous)?
- What is the rank (1-based, in lexicographic order) of the string cab among all permutations of the letters a, b, c?
- How many trailing zeros does 2024! have in base 10?
- How many integers n with 2 <= n <= 200 are square-free (not divisible by the square of any integer greater than 1)?
- What is the sum of Euler's totient phi(i) for i = 1 to 10 (phi(i) counts the integers k in [1, i] with gcd(k, i) = 1)?