Loading...
Loading...
Loading...
The Fibonacci numbers are 0, 1, 1, 2, 3, 5, ... where each number after the first two is the sum of the previous two. Use recursion with functools.lru_cache to print the nth number.
Example
Input
10
Output
55
The sequence goes 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55.
Try the problem first. Open one hint at a time.
The base case is n < 2, which returns n.
Add the cache decorator so repeated calls are looked up.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor