ProgrammingVery hardTCS NQT · Infosys
Using fib-like recursion where a stair can be climbed by 1 or 2 steps, the number of ways for 10 stairs is the recursion W(n) = W(n-1) + W(n-2) with W(0) = 1 and W(1) = 1. What is W(10)?
- A. 55
- B. 34
- C. 144
- D. 89
Correct answer: D. 89
The values run 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, so W(10) = 89. The iterative loop computes the same values with O(1) memory.
More C Programming questions
- What is sizeof "hi" in C?
- For unsigned a and b greater than 0 stored in uint32t, which test correctly detects that a b overflows?
- char words[] holds strings and must be sorted by length first and then alphabetically using qsort. Which comparator is correct?
- char buf[4]; int n = snprintf(buf, sizeof buf, "%d", 12345); What is n?
- uint8t x = 0xB7; uint8t y = x | (x + 1); What is y?
- The number of ways to tile a 2 x 6 board with 2 x 1 dominoes equals the number of binary tilings given by T(n) = T(n-1) + T(n-2) with T(1)…