Mark As Completed Discussion

One Pager Cheat Sheet

  • Implement a function fibonacci(n) which returns the number in the Fibonacci sequence where n <= 40, with a time and space complexity of O(n).
  • The Fibonacci sequence can be effectively generated using Recursion in order to efficiently calculate each successive number from the sum of the two prior.
  • By storing intermediate results and using a recursive approach, the Fibonacci Sequence can be calculated with a complexity of `O(2n)$.
  • We can memo-ize (store) previous function calls and their results by using the memoize function, which uses a hash map as a storage.
  • To improve performance in recurring algorithms, use memoize to wrap the fibonacci function.

This is our final solution.

To visualize the solution and step through the below code, click Visualize the Solution on the right-side menu or the VISUALIZE button in Interactive Mode.

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Got more time? Let's keep going.

If you had any problems with this tutorial, check out the main forum thread here.