Data Structures & AlgorithmsHardTCS NQT · Codeforces Div2 C
How many strings of length 6 over {a, b} have NO position i with s[i] = s[i+2] (for every valid i)?
- A. 6
- B. 4
- C. 64
- D. 5
Correct answer: B. 4
Each new letter must differ from the letter two positions earlier, so once the first two letters are chosen the rest is forced. Each later letter must be the other letter, so it is forced; the first two letters can be chosen in 2 × 2 = 4 ways, and the count stays 4 for every length n ≥ 2.
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 arrays of length 4 with entries from {1, 2, ..., 3} are NON-INCREASING (each entry is at least the next)?
- Daily prices are [3, 2, 6, 5, 0, 3, 8, 1, 9]. You may complete at most 3 buy-then-sell transactions (one share at a time, sell before the…
- What is the maximum sum of a non-empty contiguous subarray of [4, -6, 3, -1, 7, -2, 5] that contains AT MOST one negative element?
- What is the maximum product of exactly 3 consecutive elements of [2, -3, 4, -1, 5, -6, 2]?
- How many contiguous subarrays (of length at least 2) of [1, 3, 4, 2, 5, 6, 8, 1] are strictly increasing?
- How many subarrays (i ≤ j) of [2, 1, 2, 3, 1, 2] have their first and last elements equal? A single element counts (its first and last are…