Data Structures & AlgorithmsModerateTCS NQT Digital · Accenture
Problem: How many binary strings of length 5 contain no three consecutive 1s?
- A. 13
- B. 8
- C. 29
- D. 24
Correct answer: D. 24
a(n) = a(n−1) + a(n−2) + a(n−3) with 1, 2, 4 gives 7, 13, 24 for n = 3, 4, 5. Banning '11' gives 13, 8 counts the strings that do contain 111, and banning only '1111' gives 29.
More Coding Interview Problems questions
- Problem: Stock trading allows unlimited transactions, but after selling you must wait one day before buying (cooldown). Prices are [1, 2…
- Problem: Josephus with step 3: 10 people numbered 1 to 10 stand in a circle. Starting from person 1, count 3 people and eliminate the…
- Problem: The sequence x0 = 1 and x(n+1) = (3·x(n) + 1) mod 7 is generated. The first repeated value appears at some step. What is the…
- Problem: A ball starts at position 0 on a track from 0 to 10 and moves 3 units per second. At each boundary it reverses direction…
- Problem: The permutation [2, 1, 4, 3] is processed by a single stack: input elements are pushed in order and popped whenever the popped…
- Problem: How many integers from 1 to 500 are coprime to 30 (share no prime factor with 30 = 2·3·5)?