Home / Challenges / Optimize Fibonacci with Caching

Optimize Fibonacci with Caching

Medium
Write a function fast_fibonacci(n) that computes the nth Fibonacci number (0-indexed, fib(0)=0, fib(1)=1) using @functools.lru_cache to avoid redundant recursive calls.

Input

A non-negative integer n.

Output

The nth Fibonacci number as an integer.

Example

Input
fast_fibonacci(10)
Output
55
15 XP on solve Back to lesson

Your Solution

Output
Click "Run" to execute your code...

Log in to submit your solution and earn XP.