Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: How many binary strings of length 4 contain no two adjacent 1s?
- A. 8
- B. 13
- C. 5
- D. 16
Correct answer: A. 8
No-'11' strings follow a(n) = a(n−1) + a(n−2) with a(1) = 2, a(2) = 3, so a(4) = 8. Length 5 gives 13, length 3 gives 5, and 16 counts every string.
More Coding Interview Problems questions
- Problem: How many two-digit numbers (10–99) have digits that sum to exactly 9?
- Problem: The undirected graph on vertices 0, 1, 2 has edges 0-1 (5), 1-2 (5) and 0-2 (12). What is the shortest path length from 0 to 2?
- Problem: A complete binary tree has all levels full with depths 0 to 4 (root at depth 0). How many nodes does it have in total?
- Compute the sum of gcd(i, j) over all pairs 1 ≤ i < j ≤ 50. python from math import gcd print(sum(gcd(i,j) for i in range(1,51) for j in…
- How many integers n with 1 ≤ n ≤ 10000 have exactly four positive divisors? Count them with a divisor-count sieve. python N=10000…
- Array a = [3, 8, 2, 9, 5, 7, 6]. Count the index triples i < j < k such that the three values, sorted, are equally spaced (an arithmetic…