Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many strings of length 5 over the alphabet {a, b, c} do NOT contain the substring "abc"?
- A. 220
- B. 216
- C. 75
- D. 217
Correct answer: B. 216
A string contains 'abc' at a position i exactly when the three letters starting there match; counting strings with the substring is inclusion–exclusion over positions. Subtracting only the strings where 'abc' starts at the first position undercounts.
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 2 × 5 grid has obstacles at (row, column) positions [(0, 2), (1, 3)] (rows 0 and 1, columns 0 to 4). Starting at (0,0), you move one…
- What is the length of the longest contiguous subarray of [4, 2, 2, 6, 4] whose bitwise XOR equals 6?
- Closed integer intervals are [(1, 2), (3, 4), (2, 5), (6, 7), (8, 9)]. How many unordered pairs of these intervals are disjoint (share no…
- How many ordered ways are there to write 8 as a sum of parts, each part being 1, 2 or 3 (the order of parts matters)?
- Coins of value 2, 3 and 7 are available in unlimited supply. What is the minimum number of coins needed to make exactly 20?
- In how many ways can you choose 4 distinct numbers from 1 to 6 and list them in increasing order? (Each choice gives exactly one…