Data Structures & AlgorithmsHardGoldman Sachs OA · LeetCode medium-hard

A recursive function is defined as f(0) = f(1) = 1 and f(n) = f(n−1) + 2·f(n−2) for n ≥ 2. Using memoization, what is f(9)?

  1. A. 341
  2. B. 342
  3. C. 163
  4. D. 171

Correct answer: A. 341

Building up the memo table from f(0) = f(1) = 1 using f(n) = f(n−1) + 2·f(n−2) step by step gives f(9) = 341. 171 is actually f(8), a common off-by-one when the table is read one step too early.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic