Data Structures & AlgorithmsModerateTCS NQT · Product Company SDE
Problem: What is the number of ways to climb 8 steps when each move is 1, 2 or 4 steps, counted as ordered sequences?
- A. 55
- B. 9
- C. 81
- D. 31
Correct answer: A. 55
f(n) = f(n−1) + f(n−2) + f(n−4) gives 1, 1, 2, 3, 6, 10, 18, 31, 55, so f(8) = 55. Unordered multisets give 9, using steps 1, 2, 3 gives 81, and f(7) = 31 is one index short.
More Coding Interview Problems questions
- Problem: The array [1, 2, 3, 4, 5, 6, 7, 8, 9] is split into 3 consecutive groups of equal length. What is the sum of the middle group?
- Problem: The product of the numbers from 1 to 10, divided by the product of the numbers from 1 to 7, is what value?
- Problem: A string is "xoxoxox". How many substrings of length 3 are equal to "xox"?
- Problem: Consider the graph on vertices 1–6 with edges 1-2, 2-3, 3-4, 4-1, 5-6. What is the size of its largest connected component?
- Problem: Starting at index 0 of the array [2, 4, 1, 6, 3], repeatedly jump forward by the value at the current index (no wraparound; the…
- Problem: How many integers in the range 1 to 100 are both a multiple of 3 and have a digit sum equal to 6?