Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
How many strings of length 5 over the alphabet {a, b, c} have no two adjacent characters equal?
- A. 48
- B. 54
- C. 36
- D. 243
Correct answer: A. 48
Every valid string can be extended in exactly two ways at each step, because the next letter must differ from the previous one. So the total is 3 * 2^4 = 48; ignoring the restriction gives 3^5 = 243.
More Coding Interview Problems questions
- How many non-empty subsets of {1, 2, 3, 4, 5, 6} have an XOR of their elements that is at least 4?
- How many subsets (including the empty subset) of the values [2, 3, 5, 7, 11, 13, 4, 6] have a sum between 10 and 20 inclusive?
- The values [7, 4, 9, 2, 6, 5] are distributed among two groups (each value goes to exactly one group, any group may be empty). What is the…
- Closed intervals [1,3], [2,6], [3,5], [4,8], [7,9], [9,11], [10,12]. Two intervals conflict if they share any point, endpoints included…
- Half-open intervals [0,4), [1,3), [2,6), [5,7), [6,9), [8,10). What is the minimum number of integer points such that every interval…
- Tasks are (deadline, duration): (3, 1), (2, 2), (4, 3), (5, 2), (1, 1). Tasks run one after another from time 0 without preemption, and a…